react-scripts-intlayer 9.1.2 → 9.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/cli/react-scripts-intlayer.cjs +18 -0
- package/dist/cjs/cli/react-scripts-intlayer.cjs.map +1 -1
- package/dist/cjs/findDuplicateWebpackPaths.cjs +56 -0
- package/dist/cjs/findDuplicateWebpackPaths.cjs.map +1 -0
- package/dist/cjs/intlayerCracoPlugin.cjs +0 -1
- package/dist/cjs/intlayerCracoPlugin.cjs.map +1 -1
- package/dist/types/findDuplicateWebpackPaths.d.ts +38 -0
- package/dist/types/findDuplicateWebpackPaths.d.ts.map +1 -0
- package/dist/types/intlayerCracoPlugin.d.ts +12 -3
- package/dist/types/intlayerCracoPlugin.d.ts.map +1 -1
- package/package.json +11 -7
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
const require_findDuplicateWebpackPaths = require('../findDuplicateWebpackPaths.cjs');
|
|
2
3
|
let _intlayer_config_node = require("@intlayer/config/node");
|
|
3
4
|
let _intlayer_config_utils = require("@intlayer/config/utils");
|
|
4
5
|
let node_child_process = require("node:child_process");
|
|
@@ -15,6 +16,22 @@ const args = process.argv.slice(2);
|
|
|
15
16
|
const scriptIndex = args.findIndex((index) => index === "build" || index === "start" || index === "test");
|
|
16
17
|
const script = scriptIndex === -1 ? args[0] : args[scriptIndex];
|
|
17
18
|
/**
|
|
19
|
+
* Surface a duplicated webpack install up-front, instead of leaving the user
|
|
20
|
+
* with the unactionable `TypeError: The 'compilation' argument must be an
|
|
21
|
+
* instance of Compilation` stack trace webpack throws much later.
|
|
22
|
+
*/
|
|
23
|
+
const warnOnDuplicateWebpack = () => {
|
|
24
|
+
const duplicateWebpackPaths = require_findDuplicateWebpackPaths.findDuplicateWebpackPaths();
|
|
25
|
+
if (duplicateWebpackPaths.length === 0) return;
|
|
26
|
+
(0, _intlayer_config_logger.logger)([
|
|
27
|
+
"Multiple copies of webpack were found in this project:",
|
|
28
|
+
...duplicateWebpackPaths.map((webpackPath) => ` - ${webpackPath}`),
|
|
29
|
+
"",
|
|
30
|
+
"react-scripts and its plugins must share a single webpack instance, otherwise the build fails with \"The 'compilation' argument must be an instance of Compilation\".",
|
|
31
|
+
"Deduplicate the install — for example by removing node_modules and the lockfile and reinstalling, or by pinning a single webpack version through your package manager (npm `overrides`, yarn `resolutions`, pnpm/bun `overrides`)."
|
|
32
|
+
].join("\n"), { level: "warn" });
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
18
35
|
* Build the Intlayer dictionaries (i.e. populate the `.intlayer` folder that
|
|
19
36
|
* backs the `@intlayer/dictionaries-entry` alias) before craco/webpack starts.
|
|
20
37
|
*
|
|
@@ -39,6 +56,7 @@ const runScript = async () => {
|
|
|
39
56
|
(0, _intlayer_config_logger.logger)("Perhaps you need to update craco?");
|
|
40
57
|
return;
|
|
41
58
|
}
|
|
59
|
+
warnOnDuplicateWebpack();
|
|
42
60
|
await prepareDictionaries(script);
|
|
43
61
|
const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : [];
|
|
44
62
|
const scriptPath = (0, _intlayer_config_utils.getProjectRequire)().resolve(`@craco/craco/dist/scripts/${script}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-scripts-intlayer.cjs","names":[],"sources":["../../../src/cli/react-scripts-intlayer.ts"],"sourcesContent":["#!/usr/bin/env node\n\n/**\n * To make the setup easier, we are using craco to override the webpack configuration.\n * This script is used to run the craco scripts with the custom configuration.\n *\n * The script is based on the original craco script from create-react-app.\n */\n\nimport { spawnSync } from 'node:child_process';\nimport { logger } from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\nimport { getProjectRequire } from '@intlayer/config/utils';\n\nconst args = process.argv.slice(2);\nconst scriptIndex = args.findIndex(\n (index) => index === 'build' || index === 'start' || index === 'test'\n);\nconst script = scriptIndex === -1 ? args[0] : args[scriptIndex];\n\n/**\n * Build the Intlayer dictionaries (i.e. populate the `.intlayer` folder that\n * backs the `@intlayer/dictionaries-entry` alias) before craco/webpack starts.\n *\n * Unlike the webpack `IntlayerPlugin` — whose `beforeCompile` hook fires only\n * after webpack has already begun resolving modules — this runs ahead of the\n * compiler so the dictionaries entry exists the moment resolution starts.\n * Mirrors the async `withIntlayer` flow used by the Next.js integration.\n */\nconst prepareDictionaries = async (\n currentScript: string | undefined\n): Promise<void> => {\n // `start` runs the dev server, `build` a production bundle, `test` the suite.\n const isBuild = currentScript === 'build';\n const isDev = currentScript === 'start';\n\n const { prepareIntlayer } = await import('@intlayer/engine/build');\n const intlayerConfig = getConfiguration();\n\n // `prepareIntlayer` uses `runOnce`, so a redundant call from the webpack\n // plugin later in the pipeline is a cheap no-op.\n await prepareIntlayer(intlayerConfig, {\n clean: isBuild,\n env: isBuild ? 'prod' : 'dev',\n cacheTimeoutMs: isDev\n ? 1000 * 60 * 60 // 1 hour for dev (default cache timeout)\n : 1000 * 30, // 30 seconds for build/test (ensure dictionaries are fresh)\n });\n};\n\nconst runScript = async (): Promise<void> => {\n if (script !== 'build' && script !== 'start' && script !== 'test') {\n logger(`Unknown script \"${script}\".`);\n logger('Perhaps you need to update craco?');\n return;\n }\n\n await prepareDictionaries(script);\n\n const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : [];\n const scriptPath = getProjectRequire().resolve(\n `@craco/craco/dist/scripts/${script}`\n );\n\n const scriptArgs = args.slice(scriptIndex + 1);\n const processArgs = nodeArgs\n .concat(scriptPath)\n .concat([\n ...scriptArgs,\n '--config',\n './node_modules/react-scripts-intlayer/dist/cjs/craco.config.cjs',\n ]);\n\n const child = spawnSync('node', processArgs, {\n stdio: 'inherit',\n });\n\n if (child.signal) {\n if (child.signal === 'SIGKILL') {\n logger(`\n The build failed because the process exited too early.\n This probably means the system ran out of memory or someone called\n \\`kill -9\\` on the process.\n `);\n } else if (child.signal === 'SIGTERM') {\n logger(`\n The build failed because the process exited too early.\n Someone might have called \\`kill\\` or \\`killall\\`, or the system could\n be shutting down.\n `);\n }\n\n process.exit(1);\n }\n\n process.exit(child.status ?? undefined);\n};\n\nrunScript();\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"react-scripts-intlayer.cjs","names":["findDuplicateWebpackPaths"],"sources":["../../../src/cli/react-scripts-intlayer.ts"],"sourcesContent":["#!/usr/bin/env node\n\n/**\n * To make the setup easier, we are using craco to override the webpack configuration.\n * This script is used to run the craco scripts with the custom configuration.\n *\n * The script is based on the original craco script from create-react-app.\n */\n\nimport { spawnSync } from 'node:child_process';\nimport { logger } from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\nimport { getProjectRequire } from '@intlayer/config/utils';\nimport { findDuplicateWebpackPaths } from '../findDuplicateWebpackPaths';\n\nconst args = process.argv.slice(2);\nconst scriptIndex = args.findIndex(\n (index) => index === 'build' || index === 'start' || index === 'test'\n);\nconst script = scriptIndex === -1 ? args[0] : args[scriptIndex];\n\n/**\n * Surface a duplicated webpack install up-front, instead of leaving the user\n * with the unactionable `TypeError: The 'compilation' argument must be an\n * instance of Compilation` stack trace webpack throws much later.\n */\nconst warnOnDuplicateWebpack = (): void => {\n const duplicateWebpackPaths = findDuplicateWebpackPaths();\n\n if (duplicateWebpackPaths.length === 0) return;\n\n logger(\n [\n 'Multiple copies of webpack were found in this project:',\n ...duplicateWebpackPaths.map((webpackPath) => ` - ${webpackPath}`),\n '',\n 'react-scripts and its plugins must share a single webpack instance, otherwise the build fails with \"The \\'compilation\\' argument must be an instance of Compilation\".',\n 'Deduplicate the install — for example by removing node_modules and the lockfile and reinstalling, or by pinning a single webpack version through your package manager (npm `overrides`, yarn `resolutions`, pnpm/bun `overrides`).',\n ].join('\\n'),\n { level: 'warn' }\n );\n};\n\n/**\n * Build the Intlayer dictionaries (i.e. populate the `.intlayer` folder that\n * backs the `@intlayer/dictionaries-entry` alias) before craco/webpack starts.\n *\n * Unlike the webpack `IntlayerPlugin` — whose `beforeCompile` hook fires only\n * after webpack has already begun resolving modules — this runs ahead of the\n * compiler so the dictionaries entry exists the moment resolution starts.\n * Mirrors the async `withIntlayer` flow used by the Next.js integration.\n */\nconst prepareDictionaries = async (\n currentScript: string | undefined\n): Promise<void> => {\n // `start` runs the dev server, `build` a production bundle, `test` the suite.\n const isBuild = currentScript === 'build';\n const isDev = currentScript === 'start';\n\n const { prepareIntlayer } = await import('@intlayer/engine/build');\n const intlayerConfig = getConfiguration();\n\n // `prepareIntlayer` uses `runOnce`, so a redundant call from the webpack\n // plugin later in the pipeline is a cheap no-op.\n await prepareIntlayer(intlayerConfig, {\n clean: isBuild,\n env: isBuild ? 'prod' : 'dev',\n cacheTimeoutMs: isDev\n ? 1000 * 60 * 60 // 1 hour for dev (default cache timeout)\n : 1000 * 30, // 30 seconds for build/test (ensure dictionaries are fresh)\n });\n};\n\nconst runScript = async (): Promise<void> => {\n if (script !== 'build' && script !== 'start' && script !== 'test') {\n logger(`Unknown script \"${script}\".`);\n logger('Perhaps you need to update craco?');\n return;\n }\n\n warnOnDuplicateWebpack();\n\n await prepareDictionaries(script);\n\n const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : [];\n const scriptPath = getProjectRequire().resolve(\n `@craco/craco/dist/scripts/${script}`\n );\n\n const scriptArgs = args.slice(scriptIndex + 1);\n const processArgs = nodeArgs\n .concat(scriptPath)\n .concat([\n ...scriptArgs,\n '--config',\n './node_modules/react-scripts-intlayer/dist/cjs/craco.config.cjs',\n ]);\n\n const child = spawnSync('node', processArgs, {\n stdio: 'inherit',\n });\n\n if (child.signal) {\n if (child.signal === 'SIGKILL') {\n logger(`\n The build failed because the process exited too early.\n This probably means the system ran out of memory or someone called\n \\`kill -9\\` on the process.\n `);\n } else if (child.signal === 'SIGTERM') {\n logger(`\n The build failed because the process exited too early.\n Someone might have called \\`kill\\` or \\`killall\\`, or the system could\n be shutting down.\n `);\n }\n\n process.exit(1);\n }\n\n process.exit(child.status ?? undefined);\n};\n\nrunScript();\n"],"mappings":";;;;;;;;;;;;;;AAeA,MAAM,OAAO,QAAQ,KAAK,MAAM,CAAC;AACjC,MAAM,cAAc,KAAK,WACtB,UAAU,UAAU,WAAW,UAAU,WAAW,UAAU,MACjE;AACA,MAAM,SAAS,gBAAgB,KAAK,KAAK,KAAK,KAAK;;;;;;AAOnD,MAAM,+BAAqC;CACzC,MAAM,wBAAwBA,4DAA0B;CAExD,IAAI,sBAAsB,WAAW,GAAG;CAExC,oCACE;EACE;EACA,GAAG,sBAAsB,KAAK,gBAAgB,OAAO,aAAa;EAClE;EACA;EACA;CACF,CAAC,CAAC,KAAK,IAAI,GACX,EAAE,OAAO,OAAO,CAClB;AACF;;;;;;;;;;AAWA,MAAM,sBAAsB,OAC1B,kBACkB;CAElB,MAAM,UAAU,kBAAkB;CAClC,MAAM,QAAQ,kBAAkB;CAEhC,MAAM,EAAE,oBAAoB,MAAM,OAAO;CAKzC,MAAM,4DAA6B,GAAG;EACpC,OAAO;EACP,KAAK,UAAU,SAAS;EACxB,gBAAgB,QACZ,MAAO,KAAK,KACZ,MAAO;CACb,CAAC;AACH;AAEA,MAAM,YAAY,YAA2B;CAC3C,IAAI,WAAW,WAAW,WAAW,WAAW,WAAW,QAAQ;EACjE,oCAAO,mBAAmB,OAAO,GAAG;EACpC,oCAAO,mCAAmC;EAC1C;CACF;CAEA,uBAAuB;CAEvB,MAAM,oBAAoB,MAAM;CAEhC,MAAM,WAAW,cAAc,IAAI,KAAK,MAAM,GAAG,WAAW,IAAI,CAAC;CACjE,MAAM,2DAA+B,CAAC,CAAC,QACrC,6BAA6B,QAC/B;CAEA,MAAM,aAAa,KAAK,MAAM,cAAc,CAAC;CAS7C,MAAM,0CAAkB,QARJ,SACjB,OAAO,UAAU,CAAC,CAClB,OAAO;EACN,GAAG;EACH;EACA;CACF,CAEwC,GAAG,EAC3C,OAAO,UACT,CAAC;CAED,IAAI,MAAM,QAAQ;EAChB,IAAI,MAAM,WAAW,WACnB,oCAAO;;;;aAIA;OACF,IAAI,MAAM,WAAW,WAC1B,oCAAO;;;;aAIA;EAGT,QAAQ,KAAK,CAAC;CAChB;CAEA,QAAQ,KAAK,MAAM,UAAU,MAAS;AACxC;AAEA,UAAU"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
let _intlayer_config_utils = require("@intlayer/config/utils");
|
|
3
|
+
let node_module = require("node:module");
|
|
4
|
+
|
|
5
|
+
//#region src/findDuplicateWebpackPaths.ts
|
|
6
|
+
/**
|
|
7
|
+
* Packages whose webpack resolution must agree for a CRA build to succeed.
|
|
8
|
+
*
|
|
9
|
+
* `react-scripts` owns the compiler, while `webpack-manifest-plugin` is a
|
|
10
|
+
* plugin that taps it. Both are resolved independently by Node, so a hoisting
|
|
11
|
+
* split between them is exactly the situation that breaks the build.
|
|
12
|
+
*/
|
|
13
|
+
const WEBPACK_CONSUMER_PACKAGES = ["react-scripts", "webpack-manifest-plugin"];
|
|
14
|
+
/**
|
|
15
|
+
* Resolve `webpack` from a package's own resolution root, mirroring what Node
|
|
16
|
+
* does at runtime when that package calls `require('webpack')`.
|
|
17
|
+
*
|
|
18
|
+
* @param packageName - Name of the package to resolve `webpack` on behalf of.
|
|
19
|
+
* @returns Absolute path to the webpack entry point, or `undefined` when it
|
|
20
|
+
* cannot be resolved.
|
|
21
|
+
*/
|
|
22
|
+
const resolveWebpackFrom = (packageName) => {
|
|
23
|
+
try {
|
|
24
|
+
return (0, node_module.createRequire)((0, _intlayer_config_utils.getProjectRequire)().resolve(`${packageName}/package.json`)).resolve("webpack");
|
|
25
|
+
} catch {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Detect whether the project tree contains more than one copy of webpack.
|
|
31
|
+
*
|
|
32
|
+
* `react-scripts` resolves webpack relative to itself, while hoisted plugins
|
|
33
|
+
* such as `webpack-manifest-plugin` resolve it from the project root. When the
|
|
34
|
+
* two resolutions land on different copies, the plugin's `Compilation` class is
|
|
35
|
+
* not the one the compiler instantiated and webpack throws the opaque
|
|
36
|
+
* `TypeError: The 'compilation' argument must be an instance of Compilation`.
|
|
37
|
+
*
|
|
38
|
+
* Neither `resolve.alias` nor any other webpack setting can fix this — the
|
|
39
|
+
* duplication happens in Node's own `require` resolution, before webpack ever
|
|
40
|
+
* runs — so the only remedy is deduplicating the install.
|
|
41
|
+
*
|
|
42
|
+
* @param resolver - Resolves the webpack entry a given package would load.
|
|
43
|
+
* Injectable for testing; defaults to real Node resolution.
|
|
44
|
+
* @returns The distinct webpack entry points found, in discovery order. A
|
|
45
|
+
* result of fewer than two entries means the install is consistent.
|
|
46
|
+
*/
|
|
47
|
+
const findDuplicateWebpackPaths = (resolver = resolveWebpackFrom) => {
|
|
48
|
+
const webpackPaths = WEBPACK_CONSUMER_PACKAGES.map(resolver).filter((webpackPath) => Boolean(webpackPath));
|
|
49
|
+
const uniqueWebpackPaths = [...new Set(webpackPaths)];
|
|
50
|
+
return uniqueWebpackPaths.length < 2 ? [] : uniqueWebpackPaths;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
//#endregion
|
|
54
|
+
exports.findDuplicateWebpackPaths = findDuplicateWebpackPaths;
|
|
55
|
+
exports.resolveWebpackFrom = resolveWebpackFrom;
|
|
56
|
+
//# sourceMappingURL=findDuplicateWebpackPaths.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"findDuplicateWebpackPaths.cjs","names":[],"sources":["../../src/findDuplicateWebpackPaths.ts"],"sourcesContent":["import { createRequire } from 'node:module';\nimport { getProjectRequire } from '@intlayer/config/utils';\n\n/**\n * Packages whose webpack resolution must agree for a CRA build to succeed.\n *\n * `react-scripts` owns the compiler, while `webpack-manifest-plugin` is a\n * plugin that taps it. Both are resolved independently by Node, so a hoisting\n * split between them is exactly the situation that breaks the build.\n */\nconst WEBPACK_CONSUMER_PACKAGES = ['react-scripts', 'webpack-manifest-plugin'];\n\n/**\n * Resolves a function that maps a package name to the `webpack` entry point\n * that package would load, or `undefined` when the package (or its webpack) is\n * not installed.\n */\nexport type WebpackResolver = (packageName: string) => string | undefined;\n\n/**\n * Resolve `webpack` from a package's own resolution root, mirroring what Node\n * does at runtime when that package calls `require('webpack')`.\n *\n * @param packageName - Name of the package to resolve `webpack` on behalf of.\n * @returns Absolute path to the webpack entry point, or `undefined` when it\n * cannot be resolved.\n */\nexport const resolveWebpackFrom: WebpackResolver = (packageName) => {\n try {\n const packageJsonPath = getProjectRequire().resolve(\n `${packageName}/package.json`\n );\n\n return createRequire(packageJsonPath).resolve('webpack');\n } catch {\n // The package (or its webpack) is absent — nothing to compare.\n return undefined;\n }\n};\n\n/**\n * Detect whether the project tree contains more than one copy of webpack.\n *\n * `react-scripts` resolves webpack relative to itself, while hoisted plugins\n * such as `webpack-manifest-plugin` resolve it from the project root. When the\n * two resolutions land on different copies, the plugin's `Compilation` class is\n * not the one the compiler instantiated and webpack throws the opaque\n * `TypeError: The 'compilation' argument must be an instance of Compilation`.\n *\n * Neither `resolve.alias` nor any other webpack setting can fix this — the\n * duplication happens in Node's own `require` resolution, before webpack ever\n * runs — so the only remedy is deduplicating the install.\n *\n * @param resolver - Resolves the webpack entry a given package would load.\n * Injectable for testing; defaults to real Node resolution.\n * @returns The distinct webpack entry points found, in discovery order. A\n * result of fewer than two entries means the install is consistent.\n */\nexport const findDuplicateWebpackPaths = (\n resolver: WebpackResolver = resolveWebpackFrom\n): string[] => {\n const webpackPaths = WEBPACK_CONSUMER_PACKAGES.map(resolver).filter(\n (webpackPath): webpackPath is string => Boolean(webpackPath)\n );\n\n const uniqueWebpackPaths = [...new Set(webpackPaths)];\n\n return uniqueWebpackPaths.length < 2 ? [] : uniqueWebpackPaths;\n};\n"],"mappings":";;;;;;;;;;;;AAUA,MAAM,4BAA4B,CAAC,iBAAiB,yBAAyB;;;;;;;;;AAiB7E,MAAa,sBAAuC,gBAAgB;CAClE,IAAI;EAKF,oFAJ0C,CAAC,CAAC,QAC1C,GAAG,YAAY,cAGkB,CAAC,CAAC,CAAC,QAAQ,SAAS;CACzD,QAAQ;EAEN;CACF;AACF;;;;;;;;;;;;;;;;;;;AAoBA,MAAa,6BACX,WAA4B,uBACf;CACb,MAAM,eAAe,0BAA0B,IAAI,QAAQ,CAAC,CAAC,QAC1D,gBAAuC,QAAQ,WAAW,CAC7D;CAEA,MAAM,qBAAqB,CAAC,GAAG,IAAI,IAAI,YAAY,CAAC;CAEpD,OAAO,mBAAmB,SAAS,IAAI,CAAC,IAAI;AAC9C"}
|
|
@@ -13,7 +13,6 @@ const alias = (0, _intlayer_config_utils.getAlias)({
|
|
|
13
13
|
});
|
|
14
14
|
/**
|
|
15
15
|
* Override the final CRA Webpack config.
|
|
16
|
-
* We explicitely type the return as WebpackConfig to solve TS2742.
|
|
17
16
|
*/
|
|
18
17
|
const overrideWebpackConfig = ({ webpackConfig }) => {
|
|
19
18
|
if (typeof webpackConfig.externals === "object") webpackConfig.externals = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intlayerCracoPlugin.cjs","names":["IntlayerPlugin"],"sources":["../../src/intlayerCracoPlugin.ts"],"sourcesContent":["import { join } from 'node:path';\nimport type {\n CracoConfig,\n CracoConfigOverride,\n CracoPlugin,\n WebpackConfigOverride,\n} from '@craco/types';\nimport { getConfiguration } from '@intlayer/config/node';\nimport { getAlias } from '@intlayer/config/utils';\nimport { IntlayerPlugin } from '@intlayer/webpack';\nimport { defu } from 'defu';\
|
|
1
|
+
{"version":3,"file":"intlayerCracoPlugin.cjs","names":["IntlayerPlugin"],"sources":["../../src/intlayerCracoPlugin.ts"],"sourcesContent":["import { join } from 'node:path';\nimport type {\n CracoConfig,\n CracoConfigOverride,\n CracoPlugin,\n WebpackConfigOverride,\n} from '@craco/types';\nimport { getConfiguration } from '@intlayer/config/node';\nimport { getAlias } from '@intlayer/config/utils';\nimport { IntlayerPlugin } from '@intlayer/webpack';\nimport { defu } from 'defu';\n\n/**\n * The webpack `Configuration` type exactly as CRACO hands it to us.\n *\n * Deliberately derived from `@craco/types` rather than imported from `webpack`:\n * the webpack copy CRACO resolves and the one this package resolves are two\n * distinct type identities whenever their versions differ, which makes any\n * conversion between them a compile error. Reusing CRACO's own type keeps a\n * single identity, and — being an indexed access on an imported type — it stays\n * nameable in the emitted declarations, avoiding TS2742.\n */\ntype CracoWebpackConfig = WebpackConfigOverride['webpackConfig'];\n\n// Get Intlayer configuration\nconst intlayerConfig = getConfiguration();\n\nconst alias = getAlias({\n configuration: intlayerConfig,\n formatter: (value: string) => join(process.cwd(), value),\n});\n\n/**\n * Override the final CRA Webpack config.\n */\nexport const overrideWebpackConfig = ({\n webpackConfig,\n}: WebpackConfigOverride): CracoWebpackConfig => {\n // 1) Remove `module`, `fs`, `path`, `vm` from externals.\n if (typeof webpackConfig.externals === 'object') {\n webpackConfig.externals = {\n ...webpackConfig.externals,\n esbuild: 'esbuild',\n };\n }\n\n // 2) Properly push node-loader rule\n webpackConfig.module?.rules?.push({\n test: /\\.node$/,\n use: 'node-loader',\n });\n\n return webpackConfig;\n};\n\n/**\n * Override the CRACO config itself to set up aliases, fallbacks, and plugins.\n */\nexport const overrideCracoConfig = ({\n cracoConfig,\n}: CracoConfigOverride): CracoConfig =>\n defu(\n {\n webpack: {\n plugins: {\n // defu overwrites arrays by default, so we manually preserve existing plugins\n add: [\n ...(cracoConfig.webpack?.plugins?.add ?? []),\n new IntlayerPlugin(intlayerConfig),\n ],\n },\n // Automatically merges deeply with existing aliases\n alias,\n },\n },\n cracoConfig\n ) as CracoConfig;\n\n/**\n * A CRACO plugin that adds the Intlayer configuration to the webpack configuration\n * and sets the environment variables.\n */\nexport const intlayerCracoPlugin: CracoPlugin = {\n overrideCracoConfig,\n overrideWebpackConfig,\n};\n"],"mappings":";;;;;;;;AAyBA,MAAM,6DAAkC;AAExC,MAAM,6CAAiB;CACrB,eAAe;CACf,YAAY,8BAAuB,QAAQ,IAAI,GAAG,KAAK;AACzD,CAAC;;;;AAKD,MAAa,yBAAyB,EACpC,oBAC+C;CAE/C,IAAI,OAAO,cAAc,cAAc,UACrC,cAAc,YAAY;EACxB,GAAG,cAAc;EACjB,SAAS;CACX;CAIF,cAAc,QAAQ,OAAO,KAAK;EAChC,MAAM;EACN,KAAK;CACP,CAAC;CAED,OAAO;AACT;;;;AAKA,MAAa,uBAAuB,EAClC,iCAGE,EACE,SAAS;CACP,SAAS,EAEP,KAAK,CACH,GAAI,YAAY,SAAS,SAAS,OAAO,CAAC,GAC1C,IAAIA,iCAAe,cAAc,CACnC,EACF;CAEA;AACF,EACF,GACA,WACF;;;;;AAMF,MAAa,sBAAmC;CAC9C;CACA;AACF"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
//#region src/findDuplicateWebpackPaths.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Resolves a function that maps a package name to the `webpack` entry point
|
|
4
|
+
* that package would load, or `undefined` when the package (or its webpack) is
|
|
5
|
+
* not installed.
|
|
6
|
+
*/
|
|
7
|
+
type WebpackResolver = (packageName: string) => string | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* Resolve `webpack` from a package's own resolution root, mirroring what Node
|
|
10
|
+
* does at runtime when that package calls `require('webpack')`.
|
|
11
|
+
*
|
|
12
|
+
* @param packageName - Name of the package to resolve `webpack` on behalf of.
|
|
13
|
+
* @returns Absolute path to the webpack entry point, or `undefined` when it
|
|
14
|
+
* cannot be resolved.
|
|
15
|
+
*/
|
|
16
|
+
declare const resolveWebpackFrom: WebpackResolver;
|
|
17
|
+
/**
|
|
18
|
+
* Detect whether the project tree contains more than one copy of webpack.
|
|
19
|
+
*
|
|
20
|
+
* `react-scripts` resolves webpack relative to itself, while hoisted plugins
|
|
21
|
+
* such as `webpack-manifest-plugin` resolve it from the project root. When the
|
|
22
|
+
* two resolutions land on different copies, the plugin's `Compilation` class is
|
|
23
|
+
* not the one the compiler instantiated and webpack throws the opaque
|
|
24
|
+
* `TypeError: The 'compilation' argument must be an instance of Compilation`.
|
|
25
|
+
*
|
|
26
|
+
* Neither `resolve.alias` nor any other webpack setting can fix this — the
|
|
27
|
+
* duplication happens in Node's own `require` resolution, before webpack ever
|
|
28
|
+
* runs — so the only remedy is deduplicating the install.
|
|
29
|
+
*
|
|
30
|
+
* @param resolver - Resolves the webpack entry a given package would load.
|
|
31
|
+
* Injectable for testing; defaults to real Node resolution.
|
|
32
|
+
* @returns The distinct webpack entry points found, in discovery order. A
|
|
33
|
+
* result of fewer than two entries means the install is consistent.
|
|
34
|
+
*/
|
|
35
|
+
declare const findDuplicateWebpackPaths: (resolver?: WebpackResolver) => string[];
|
|
36
|
+
//#endregion
|
|
37
|
+
export { WebpackResolver, findDuplicateWebpackPaths, resolveWebpackFrom };
|
|
38
|
+
//# sourceMappingURL=findDuplicateWebpackPaths.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"findDuplicateWebpackPaths.d.ts","names":[],"sources":["../../src/findDuplicateWebpackPaths.ts"],"mappings":";;;;;;KAiBY,mBAAmB;;;;;;;;;cAUlB,oBAAoB;;;;;;;;;;;;;;;;;;;cA+BpB,4BAAyB,WAC1B"}
|
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
import { CracoConfig, CracoConfigOverride, CracoPlugin, WebpackConfigOverride } from "@craco/types";
|
|
2
|
-
import { Configuration } from "webpack";
|
|
3
2
|
//#region src/intlayerCracoPlugin.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* The webpack `Configuration` type exactly as CRACO hands it to us.
|
|
5
|
+
*
|
|
6
|
+
* Deliberately derived from `@craco/types` rather than imported from `webpack`:
|
|
7
|
+
* the webpack copy CRACO resolves and the one this package resolves are two
|
|
8
|
+
* distinct type identities whenever their versions differ, which makes any
|
|
9
|
+
* conversion between them a compile error. Reusing CRACO's own type keeps a
|
|
10
|
+
* single identity, and — being an indexed access on an imported type — it stays
|
|
11
|
+
* nameable in the emitted declarations, avoiding TS2742.
|
|
12
|
+
*/
|
|
13
|
+
type CracoWebpackConfig = WebpackConfigOverride['webpackConfig'];
|
|
4
14
|
/**
|
|
5
15
|
* Override the final CRA Webpack config.
|
|
6
|
-
* We explicitely type the return as WebpackConfig to solve TS2742.
|
|
7
16
|
*/
|
|
8
|
-
declare const overrideWebpackConfig: ({ webpackConfig }: WebpackConfigOverride) =>
|
|
17
|
+
declare const overrideWebpackConfig: ({ webpackConfig }: WebpackConfigOverride) => CracoWebpackConfig;
|
|
9
18
|
/**
|
|
10
19
|
* Override the CRACO config itself to set up aliases, fallbacks, and plugins.
|
|
11
20
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intlayerCracoPlugin.d.ts","names":[],"sources":["../../src/intlayerCracoPlugin.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"intlayerCracoPlugin.d.ts","names":[],"sources":["../../src/intlayerCracoPlugin.ts"],"mappings":";;;;;;;;;;;;KAsBK,qBAAqB;;;;cAab,0BAAqB,iBAE/B,0BAAwB;;;;cAqBd,wBAAmB,eAE7B,wBAAsB;;;;;cAsBZ,qBAAqB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-scripts-intlayer",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.2.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Integrate Intlayer with Create React App using custom React scripts for internationalization i18n and advanced Webpack configurations",
|
|
6
6
|
"keywords": [
|
|
@@ -79,14 +79,13 @@
|
|
|
79
79
|
},
|
|
80
80
|
"dependencies": {
|
|
81
81
|
"@craco/craco": "7.1.0",
|
|
82
|
-
"@intlayer/config": "9.
|
|
83
|
-
"@intlayer/engine": "9.
|
|
84
|
-
"@intlayer/types": "9.
|
|
85
|
-
"@intlayer/webpack": "9.
|
|
82
|
+
"@intlayer/config": "9.2.0",
|
|
83
|
+
"@intlayer/engine": "9.2.0",
|
|
84
|
+
"@intlayer/types": "9.2.0",
|
|
85
|
+
"@intlayer/webpack": "9.2.0",
|
|
86
86
|
"defu": "6.1.7",
|
|
87
87
|
"node-loader": "2.1.0",
|
|
88
|
-
"process": "0.11.10"
|
|
89
|
-
"webpack": "5.108.4"
|
|
88
|
+
"process": "0.11.10"
|
|
90
89
|
},
|
|
91
90
|
"devDependencies": {
|
|
92
91
|
"@craco/types": "7.1.0",
|
|
@@ -104,6 +103,11 @@
|
|
|
104
103
|
"peerDependencies": {
|
|
105
104
|
"webpack": ">=5.0.0"
|
|
106
105
|
},
|
|
106
|
+
"peerDependenciesMeta": {
|
|
107
|
+
"webpack": {
|
|
108
|
+
"optional": true
|
|
109
|
+
}
|
|
110
|
+
},
|
|
107
111
|
"engines": {
|
|
108
112
|
"node": ">=14.18"
|
|
109
113
|
},
|