Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui5-tooling-modules): new module resolution #1087

Merged
merged 10 commits into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 4 additions & 17 deletions packages/ui5-tooling-modules/lib/rollup-plugin-pnpm-resolve.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,19 @@
const path = require("path");
const fs = require("fs");

const existsAndIsFile = function (file) {
return fs.existsSync(file) && fs.statSync(file).isFile();
};

module.exports = function ({ resolveModule } = {}) {
return {
name: "pnpm-resolve",
resolveId: function (importee, importer) {
let module = importee;
if (path.isAbsolute(importee)) {
// ignore absolute paths
return null;
} else if (importee.startsWith("./") || importee.startsWith("../")) {
// resolve relative paths
const file = path.resolve(path.dirname(importer), importee);
if (existsAndIsFile(file)) {
return file;
} else if (existsAndIsFile(`${file}.js`)) {
return `${file}.js`;
} else if (existsAndIsFile(`${file}.cjs`)) {
return `${file}.cjs`;
} else if (existsAndIsFile(`${file}.mjs`)) {
return `${file}.mjs`;
}
module = path.resolve(path.dirname(importer), importee);
}
// needs to be in sync with nodeResolve
const resolvedModule = resolveModule(importee);
// try to resolve the node module using the provided function
const resolvedModule = resolveModule(module);
//console.log(`Resolved ${importee} to ${resolvedModule}`);
return resolvedModule;
},
Expand Down
10 changes: 8 additions & 2 deletions packages/ui5-tooling-modules/lib/rollup-plugin-webcomponents.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const { lt, gte } = require("semver");
// TODO:
// - enabled - disabled mapping
// - Externalize UI5 Web Components specific code
module.exports = function ({ log, resolveModule, framework, options } = {}) {
module.exports = function ({ log, resolveModule, getPackageJson, framework, options } = {}) {
// derive the configuration from the provided options
let { skip, scoping, scopeSuffix, enrichBusyIndicator } = Object.assign({ skip: false, scoping: true, enrichBusyIndicator: false }, options);

Expand Down Expand Up @@ -50,7 +50,13 @@ module.exports = function ({ log, resolveModule, framework, options } = {}) {
if (!registryEntry) {
const packageJsonPath = resolveModule(`${npmPackage}/package.json`);
if (packageJsonPath) {
const packageJson = require(packageJsonPath);
let packageJson;
try {
packageJson = getPackageJson(packageJsonPath);
} catch (err) {
log.error(`Failed to parse package.json of ${npmPackage}`, err);
return undefined;
}
const npmPackagePath = dirname(packageJsonPath);
// check if the custom elements metadata file exists (fallback to custom-elements-internal.json for @ui5/webcomponents)
let metadataPath;
Expand Down
Loading
Loading