mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
feat: Allow dependencies to be bundled
After this, only peerDependencies are externals. Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
parent
f127a07916
commit
35965505e7
4
package-lock.json
generated
4
package-lock.json
generated
@ -37282,6 +37282,7 @@
|
|||||||
"version": "3.0.0",
|
"version": "3.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/webpack-node-externals/-/webpack-node-externals-3.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/webpack-node-externals/-/webpack-node-externals-3.0.0.tgz",
|
||||||
"integrity": "sha512-LnL6Z3GGDPht/AigwRh2dvL9PQPFQ8skEpVrWZXLWBYmqcaojHNN0onvHzie6rq7EWKrrBfPYqNEzTJgiwEQDQ==",
|
"integrity": "sha512-LnL6Z3GGDPht/AigwRh2dvL9PQPFQ8skEpVrWZXLWBYmqcaojHNN0onvHzie6rq7EWKrrBfPYqNEzTJgiwEQDQ==",
|
||||||
|
"dev": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=6"
|
"node": ">=6"
|
||||||
}
|
}
|
||||||
@ -42278,8 +42279,7 @@
|
|||||||
"tailwindcss": "^3.3.1",
|
"tailwindcss": "^3.3.1",
|
||||||
"ts-loader": "^9.4.1",
|
"ts-loader": "^9.4.1",
|
||||||
"webpack": "^5.77.0",
|
"webpack": "^5.77.0",
|
||||||
"webpack-cli": "^4.10.0",
|
"webpack-cli": "^4.10.0"
|
||||||
"webpack-node-externals": "^3.0.0"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"packages/infrastructure/webpack/node_modules/@types/estree": {
|
"packages/infrastructure/webpack/node_modules/@types/estree": {
|
||||||
|
|||||||
@ -33,7 +33,6 @@
|
|||||||
"tailwindcss": "^3.3.1",
|
"tailwindcss": "^3.3.1",
|
||||||
"ts-loader": "^9.4.1",
|
"ts-loader": "^9.4.1",
|
||||||
"webpack": "^5.77.0",
|
"webpack": "^5.77.0",
|
||||||
"webpack-cli": "^4.10.0",
|
"webpack-cli": "^4.10.0"
|
||||||
"webpack-node-externals": "^3.0.0"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
const ForkTsCheckerPlugin = require("fork-ts-checker-webpack-plugin");
|
const ForkTsCheckerPlugin = require("fork-ts-checker-webpack-plugin");
|
||||||
|
const { MakePeerDependenciesExternalPlugin } = require("./plugins/make-peer-dependencies-external");
|
||||||
const { ProtectFromImportingNonDependencies } = require("./plugins/protect-from-importing-non-dependencies");
|
const { ProtectFromImportingNonDependencies } = require("./plugins/protect-from-importing-non-dependencies");
|
||||||
|
|
||||||
module.exports = ({ entrypointFilePath, outputDirectory }) => ({
|
module.exports = ({ entrypointFilePath, outputDirectory }) => ({
|
||||||
@ -17,6 +18,7 @@ module.exports = ({ entrypointFilePath, outputDirectory }) => ({
|
|||||||
},
|
},
|
||||||
|
|
||||||
plugins: [
|
plugins: [
|
||||||
|
new MakePeerDependenciesExternalPlugin(),
|
||||||
new ProtectFromImportingNonDependencies(),
|
new ProtectFromImportingNonDependencies(),
|
||||||
|
|
||||||
new ForkTsCheckerPlugin({
|
new ForkTsCheckerPlugin({
|
||||||
@ -46,21 +48,6 @@ module.exports = ({ entrypointFilePath, outputDirectory }) => ({
|
|||||||
libraryTarget: "commonjs2",
|
libraryTarget: "commonjs2",
|
||||||
},
|
},
|
||||||
|
|
||||||
externals: [
|
|
||||||
nodeExternals({ modulesFromFile: true }),
|
|
||||||
|
|
||||||
nodeExternals({
|
|
||||||
modulesDir: path.resolve(
|
|
||||||
__dirname,
|
|
||||||
"..",
|
|
||||||
"..",
|
|
||||||
"..",
|
|
||||||
"..",
|
|
||||||
"node_modules"
|
|
||||||
),
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
|
|
||||||
externalsPresets: { node: true },
|
externalsPresets: { node: true },
|
||||||
|
|
||||||
node: {
|
node: {
|
||||||
|
|||||||
@ -0,0 +1,29 @@
|
|||||||
|
const ExternalModuleFactoryPlugin = require("webpack/lib/ExternalModuleFactoryPlugin");
|
||||||
|
const path = require("path");
|
||||||
|
|
||||||
|
const {
|
||||||
|
toModuleMatcherRegExp,
|
||||||
|
} = require("./to-module-matcher-reg-exp/to-module-matcher-reg-exp");
|
||||||
|
|
||||||
|
class MakePeerDependenciesExternalPlugin {
|
||||||
|
apply(compiler) {
|
||||||
|
compiler.hooks.compile.tap("compile", (params) => {
|
||||||
|
const peerDependencies = getPeerDependencies();
|
||||||
|
|
||||||
|
new ExternalModuleFactoryPlugin(
|
||||||
|
compiler.options.output.library.type,
|
||||||
|
peerDependencies.map(toModuleMatcherRegExp)
|
||||||
|
).apply(params.normalModuleFactory);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const getPeerDependencies = () => {
|
||||||
|
const pathToPackageJson = path.resolve(process.cwd(), "package.json");
|
||||||
|
|
||||||
|
const packageJson = require(pathToPackageJson);
|
||||||
|
|
||||||
|
return Object.keys(packageJson.peerDependencies || {});
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = { MakePeerDependenciesExternalPlugin };
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
const toModuleMatcherRegExp = x => new RegExp(`^${x}(/.*)*$`);
|
||||||
|
|
||||||
|
module.exports = { toModuleMatcherRegExp };
|
||||||
@ -0,0 +1,57 @@
|
|||||||
|
import { toModuleMatcherRegExp } from "./to-module-matcher-reg-exp";
|
||||||
|
|
||||||
|
describe('to-module-matcher-reg-exp', () => {
|
||||||
|
let regExp;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
regExp = toModuleMatcherRegExp("some-package");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('given exactly matching package, matches', () => {
|
||||||
|
const targetString = 'some-package';
|
||||||
|
|
||||||
|
const [match] = targetString.match(regExp);
|
||||||
|
|
||||||
|
expect(match).toBeTruthy()
|
||||||
|
});
|
||||||
|
|
||||||
|
it('given matching package with entrypoint, matches', () => {
|
||||||
|
const targetString = 'some-package/some-entrypoint';
|
||||||
|
|
||||||
|
const [match] = targetString.match(regExp);
|
||||||
|
|
||||||
|
expect(match).toBeTruthy()
|
||||||
|
});
|
||||||
|
|
||||||
|
it('given matching package with directory, matches', () => {
|
||||||
|
const targetString = 'some-package/some-directory/some-other-directory';
|
||||||
|
|
||||||
|
const [match] = targetString.match(regExp);
|
||||||
|
|
||||||
|
expect(match).toBeTruthy()
|
||||||
|
});
|
||||||
|
|
||||||
|
it('given package that starts with same name but is still different, does not match', () => {
|
||||||
|
const targetString = 'some-package-but-still-different';
|
||||||
|
|
||||||
|
const actual = targetString.match(regExp);
|
||||||
|
|
||||||
|
expect(actual).toBeNull()
|
||||||
|
});
|
||||||
|
|
||||||
|
it('given package that starts with something else, does not match', () => {
|
||||||
|
const targetString = 'different-some-package';
|
||||||
|
|
||||||
|
const actual = targetString.match(regExp);
|
||||||
|
|
||||||
|
expect(actual).toBeNull()
|
||||||
|
});
|
||||||
|
|
||||||
|
it('given irrelevant package, does not match', () => {
|
||||||
|
const targetString = 'some-other-package';
|
||||||
|
|
||||||
|
const actual = targetString.match(regExp);
|
||||||
|
|
||||||
|
expect(actual).toBeNull()
|
||||||
|
});
|
||||||
|
});
|
||||||
Loading…
Reference in New Issue
Block a user