Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into chore/update-top-level-changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
JAdshead authored Dec 12, 2023
2 parents de7760d + fcf1567 commit 13dd381
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ jest.mock('loader-utils', () => ({
jest.mock('read-pkg-up', () => ({
sync: () => ({
packageJson: {
// this is used for the first call for modules package.json
dependencies: {
'my-dependency': '^1.0.0',
},
// this is used on second call for the dependency package.json
version: '1.2.3',
},
}),
}));
Expand Down
7 changes: 5 additions & 2 deletions packages/one-app-bundler/webpack/loaders/externals-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@
*/
const loaderUtils = require('loader-utils');
const readPkgUp = require('read-pkg-up');
const path = require('node:path');

const { packageJson } = readPkgUp.sync();

function externalsLoader() {
const { externalName, bundleTarget } = loaderUtils.getOptions(this);
// eslint-disable-next-line global-require, import/no-dynamic-require -- need to require a package.json at runtime
const { version } = require(`${externalName}/package.json`);

const version = readPkgUp.sync({
cwd: path.resolve(process.cwd(), 'node_modules', externalName),
})?.packageJson.version;

return `\
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,25 @@
*/

const loaderUtils = require('loader-utils');
const readPkgUp = require('read-pkg-up');
const path = require('node:path');

function providedExternalsLoader(content) {
const { moduleName, providedExternals } = loaderUtils.getOptions(this);

const extendedProvidedExternals = (Array.isArray(providedExternals)
? providedExternals : Object.keys(providedExternals)).map((externalName) => {
// eslint-disable-next-line global-require, import/no-dynamic-require -- need to require a package.json at runtime
const externalPkg = require(`${externalName}/package.json`);
const version = readPkgUp.sync({
cwd: path.resolve(process.cwd(), 'node_modules', externalName),
})?.packageJson.version;

return `
'${externalName}': {
...${JSON.stringify({
fallbackEnabled: false,
...providedExternals[externalName],
}, null, 2)},
version: '${externalPkg.version}',
version: '${version}',
module: require('${externalName}'),
}`;
}, {});
Expand Down

0 comments on commit 13dd381

Please sign in to comment.