@ms-cloudpack/bundler-utilities 0.5.12 → 0.6.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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSwcConfig.d.ts","sourceRoot":"","sources":["../src/getSwcConfig.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAkB,MAAM,IAAI,SAAS,EAAkB,MAAM,WAAW,CAAC;AAOrF,UAAU,kBAAkB;IAC1B,iDAAiD;IACjD,WAAW,EAAE,MAAM,CAAC;IACpB,qCAAqC;IACrC,SAAS,EAAE,OAAO,GAAG,SAAS,CAAC;CAChC;AAkBD;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,kBAAkB,GAAG;IACxD,wCAAwC;IACxC,GAAG,EAAE,SAAS,CAAC;IACf,wCAAwC;IACxC,GAAG,EAAE,SAAS,CAAC;CAChB,
|
|
1
|
+
{"version":3,"file":"getSwcConfig.d.ts","sourceRoot":"","sources":["../src/getSwcConfig.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAkB,MAAM,IAAI,SAAS,EAAkB,MAAM,WAAW,CAAC;AAOrF,UAAU,kBAAkB;IAC1B,iDAAiD;IACjD,WAAW,EAAE,MAAM,CAAC;IACpB,qCAAqC;IACrC,SAAS,EAAE,OAAO,GAAG,SAAS,CAAC;CAChC;AAkBD;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,kBAAkB,GAAG;IACxD,wCAAwC;IACxC,GAAG,EAAE,SAAS,CAAC;IACf,wCAAwC;IACxC,GAAG,EAAE,SAAS,CAAC;CAChB,CA4DA"}
|
package/lib/getSwcConfig.js
CHANGED
|
@@ -70,6 +70,9 @@ export function getSwcConfig(params) {
|
|
|
70
70
|
if (result.jsc && result.jsc?.baseUrl && !path.isAbsolute(result.jsc.baseUrl)) {
|
|
71
71
|
result.jsc.baseUrl = path.join(packagePath, result.jsc.baseUrl);
|
|
72
72
|
}
|
|
73
|
+
else if (result.jsc && !result.jsc?.baseUrl) {
|
|
74
|
+
result.jsc.baseUrl = packagePath;
|
|
75
|
+
}
|
|
73
76
|
// minifying should be up to the bundler
|
|
74
77
|
delete result.jsc?.minify;
|
|
75
78
|
// env conflicts with jsc.target -- currently we only use target
|
package/lib/getSwcConfig.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSwcConfig.js","sourceRoot":"","sources":["../src/getSwcConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAE/D,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AASrD,kCAAkC;AAClC,MAAM,kBAAkB,GAAG,CAAC,MAA6C,EAAa,EAAE,CAAC,CAAC;IACxF,GAAG,EAAE;QACH,MAAM,EAAE,mBAAmB;QAC3B,oEAAoE;QACpE,eAAe,EAAE,KAAK;KACvB;IACD,MAAM,EAAE;QACN,IAAI,EAAE,KAAK;KACZ;IACD,UAAU,EAAE,MAAM,CAAC,SAAS;CAC7B,CAAC,CAAC;AAEH,MAAM,eAAe,GAAc,EAAE,GAAG,EAAE,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;AAC5F,MAAM,eAAe,GAAc,EAAE,GAAG,EAAE,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;AAE5F;;;;;;;;;;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,CAAC,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC,CAAC;IAE5G;;;OAGG;IACH,IAAI,MAAM,CAAC,GAAG,IAAI,MAAM,CAAC,GAAG,EAAE,OAAO,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;QAC9E,MAAM,CAAC,GAAG,CAAC,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAClE,CAAC;IAED,wCAAwC;IACxC,OAAO,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC;IAC1B,gEAAgE;IAChE,oDAAoD;IACpD,OAAO,MAAM,CAAC,GAAG,CAAC;IAClB,uEAAuE;IACvE,OAAQ,MAAM,CAAC,GAAG,EAAE,MAAyB,EAAE,GAAG,CAAC;IACnD,OAAQ,MAAM,CAAC,GAAG,EAAE,MAAyB,EAAE,GAAG,CAAC;IAEnD,OAAO;QACL,GAAG,EAAE,YAAY,CAAC,CAAC,MAAM,EAAE,eAAe,CAAC,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC;QACzE,GAAG,EAAE,YAAY,CAAC,CAAC,MAAM,EAAE,eAAe,CAAC,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC;KAC1E,CAAC;AACJ,CAAC","sourcesContent":["import { readJsonSync } from '@ms-cloudpack/json-utilities';\nimport { mergeObjects } from '@ms-cloudpack/package-utilities';\nimport type { EsParserConfig, Config as SwcConfig, TsParserConfig } from '@swc/core';\nimport fs from 'fs';\nimport { parseTsconfig } from 'get-tsconfig';\nimport path from 'path';\nimport { convertTsConfig } from 'tsconfig-to-swcconfig';\nimport { defaultTargetSyntax } from './constants.js';\n\ninterface GetSwcConfigParams {\n /** Absolute path to the package (`inputPath`) */\n packagePath: string;\n /** Whether to generate sourcemaps */\n sourcemap: boolean | undefined;\n}\n\n/** Overrides all other configs */\nconst getUniversalConfig = (params: Pick<GetSwcConfigParams, 'sourcemap'>): SwcConfig => ({\n jsc: {\n target: defaultTargetSyntax,\n // We can't reference the separate @swc/helpers package from bundles\n externalHelpers: false,\n },\n module: {\n type: 'es6',\n },\n sourceMaps: params.sourcemap,\n});\n\nconst jsxParserConfig: SwcConfig = { jsc: { parser: { syntax: 'ecmascript', jsx: true } } };\nconst tsxParserConfig: SwcConfig = { jsc: { parser: { syntax: 'typescript', tsx: true } } };\n\n/**\n * Gets the SWC configuration for a package, either from `.swcrc`(`.json`), by converting\n * `tsconfig.json`, or using some basic default options.\n * (Any unset options will use [swc defaults](https://swc.rs/docs/configuration/swcrc).)\n *\n * Notably, this will use a higher default target level than the default SWC config to reduce\n * unnecessary downleveling, and override various options that are required for how cloudpack works.\n *\n * (ori/esbuild has similar behavior of implicitly reading `tsconfig.json` and using that for\n * certain transpilation settings.)\n *\n * @returns JS/TS variants of the config, to avoid processing any config files twice.\n */\nexport function getSwcConfig(params: GetSwcConfigParams): {\n /** Config for `.js` and `.jsx` files */\n jsx: SwcConfig;\n /** Config for `.ts` and `.tsx` files */\n tsx: SwcConfig;\n} {\n const { packagePath } = params;\n\n // First try reading .swcrc(.json).\n // (It might have comments but doesn't have config extension, at least in v1.)\n const swcrc: SwcConfig | SwcConfig[] | undefined =\n readJsonSync(path.join(packagePath, '.swcrc'), { mode: 'permissive' }) ||\n readJsonSync(path.join(packagePath, '.swcrc.json'), { mode: 'permissive' });\n\n let packageConfig: SwcConfig | undefined;\n // .swcrc can have either a single object or an array with `test`.\n // Possibly we could add some logic to handle the array based on file extensions\n // https://swc.rs/docs/configuration/compilation#multiple-entries\n if (Array.isArray(swcrc)) {\n console.warn(\n `Found array in .swcrc at ${packagePath} - this is not currently supported, so default settings will be used instead.`,\n );\n } else if (swcrc) {\n console.debug(`Found .swcrc at ${packagePath}`);\n packageConfig = swcrc;\n }\n\n const tsconfigPath = path.join(packagePath, 'tsconfig.json');\n if (!packageConfig && fs.existsSync(tsconfigPath)) {\n // Read tsconfig.json from the package path if present, and convert it to swc config.\n // (We use a separate read step instead of calling all-in-one tsconfig-to-swcconfig `convert()`\n // because that searches up parent dirs for a tsconfig.json, which is worse for perf.)\n try {\n const tsconfig = parseTsconfig(tsconfigPath);\n packageConfig = convertTsConfig(tsconfig.compilerOptions || {}, undefined, packagePath);\n } catch {\n // ignore\n }\n }\n\n const result = mergeObjects([packageConfig || {}, getUniversalConfig(params)], { arrayMerge: 'overwrite' });\n\n /**\n * Check if baseUrl is relative and convert it to absolute path\n * Swc doesn't support relative baseUrl paths\n */\n if (result.jsc && result.jsc?.baseUrl && !path.isAbsolute(result.jsc.baseUrl)) {\n result.jsc.baseUrl = path.join(packagePath, result.jsc.baseUrl);\n }\n\n // minifying should be up to the bundler\n delete result.jsc?.minify;\n // env conflicts with jsc.target -- currently we only use target\n // https://swc.rs/docs/configuration/compilation#env\n delete result.env;\n // delete jsx/tsx options (will apply the correct one in the last step)\n delete (result.jsc?.parser as TsParserConfig)?.tsx;\n delete (result.jsc?.parser as EsParserConfig)?.jsx;\n\n return {\n jsx: mergeObjects([result, jsxParserConfig], { arrayMerge: 'overwrite' }),\n tsx: mergeObjects([result, tsxParserConfig], { arrayMerge: 'overwrite' }),\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"getSwcConfig.js","sourceRoot":"","sources":["../src/getSwcConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAE/D,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AASrD,kCAAkC;AAClC,MAAM,kBAAkB,GAAG,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,MAAM,CAAC,GAAG,EAAE,MAAyB,EAAE,GAAG,CAAC;IAEnD,OAAO;QACL,GAAG,EAAE,YAAY,CAAC,CAAC,MAAM,EAAE,eAAe,CAAC,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC;QACzE,GAAG,EAAE,YAAY,CAAC,CAAC,MAAM,EAAE,eAAe,CAAC,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC;KAC1E,CAAC;AACJ,CAAC","sourcesContent":["import { readJsonSync } from '@ms-cloudpack/json-utilities';\nimport { mergeObjects } from '@ms-cloudpack/package-utilities';\nimport type { EsParserConfig, Config as SwcConfig, TsParserConfig } from '@swc/core';\nimport fs from 'fs';\nimport { parseTsconfig } from 'get-tsconfig';\nimport path from 'path';\nimport { convertTsConfig } from 'tsconfig-to-swcconfig';\nimport { defaultTargetSyntax } from './constants.js';\n\ninterface GetSwcConfigParams {\n /** Absolute path to the package (`inputPath`) */\n packagePath: string;\n /** Whether to generate sourcemaps */\n sourcemap: boolean | undefined;\n}\n\n/** Overrides all other configs */\nconst getUniversalConfig = (params: Pick<GetSwcConfigParams, 'sourcemap'>): SwcConfig => ({\n jsc: {\n target: defaultTargetSyntax,\n // We can't reference the separate @swc/helpers package from bundles\n externalHelpers: false,\n },\n module: {\n type: 'es6',\n },\n sourceMaps: params.sourcemap,\n});\n\nconst jsxParserConfig: SwcConfig = { jsc: { parser: { syntax: 'ecmascript', jsx: true } } };\nconst tsxParserConfig: SwcConfig = { jsc: { parser: { syntax: 'typescript', tsx: true } } };\n\n/**\n * Gets the SWC configuration for a package, either from `.swcrc`(`.json`), by converting\n * `tsconfig.json`, or using some basic default options.\n * (Any unset options will use [swc defaults](https://swc.rs/docs/configuration/swcrc).)\n *\n * Notably, this will use a higher default target level than the default SWC config to reduce\n * unnecessary downleveling, and override various options that are required for how cloudpack works.\n *\n * (ori/esbuild has similar behavior of implicitly reading `tsconfig.json` and using that for\n * certain transpilation settings.)\n *\n * @returns JS/TS variants of the config, to avoid processing any config files twice.\n */\nexport function getSwcConfig(params: GetSwcConfigParams): {\n /** Config for `.js` and `.jsx` files */\n jsx: SwcConfig;\n /** Config for `.ts` and `.tsx` files */\n tsx: SwcConfig;\n} {\n const { packagePath } = params;\n\n // First try reading .swcrc(.json).\n // (It might have comments but doesn't have config extension, at least in v1.)\n const swcrc: SwcConfig | SwcConfig[] | undefined =\n readJsonSync(path.join(packagePath, '.swcrc'), { mode: 'permissive' }) ||\n readJsonSync(path.join(packagePath, '.swcrc.json'), { mode: 'permissive' });\n\n let packageConfig: SwcConfig | undefined;\n // .swcrc can have either a single object or an array with `test`.\n // Possibly we could add some logic to handle the array based on file extensions\n // https://swc.rs/docs/configuration/compilation#multiple-entries\n if (Array.isArray(swcrc)) {\n console.warn(\n `Found array in .swcrc at ${packagePath} - this is not currently supported, so default settings will be used instead.`,\n );\n } else if (swcrc) {\n console.debug(`Found .swcrc at ${packagePath}`);\n packageConfig = swcrc;\n }\n\n const tsconfigPath = path.join(packagePath, 'tsconfig.json');\n if (!packageConfig && fs.existsSync(tsconfigPath)) {\n // Read tsconfig.json from the package path if present, and convert it to swc config.\n // (We use a separate read step instead of calling all-in-one tsconfig-to-swcconfig `convert()`\n // because that searches up parent dirs for a tsconfig.json, which is worse for perf.)\n try {\n const tsconfig = parseTsconfig(tsconfigPath);\n packageConfig = convertTsConfig(tsconfig.compilerOptions || {}, undefined, packagePath);\n } catch {\n // ignore\n }\n }\n\n const result = mergeObjects([packageConfig || {}, getUniversalConfig(params)], { arrayMerge: 'overwrite' });\n\n /**\n * Check if baseUrl is relative and convert it to absolute path\n * Swc doesn't support relative baseUrl paths\n */\n if (result.jsc && result.jsc?.baseUrl && !path.isAbsolute(result.jsc.baseUrl)) {\n result.jsc.baseUrl = path.join(packagePath, result.jsc.baseUrl);\n } else if (result.jsc && !result.jsc?.baseUrl) {\n result.jsc.baseUrl = packagePath;\n }\n\n // minifying should be up to the bundler\n delete result.jsc?.minify;\n // env conflicts with jsc.target -- currently we only use target\n // https://swc.rs/docs/configuration/compilation#env\n delete result.env;\n // delete jsx/tsx options (will apply the correct one in the last step)\n delete (result.jsc?.parser as TsParserConfig)?.tsx;\n delete (result.jsc?.parser as EsParserConfig)?.jsx;\n\n return {\n jsx: mergeObjects([result, jsxParserConfig], { arrayMerge: 'overwrite' }),\n tsx: mergeObjects([result, tsxParserConfig], { arrayMerge: 'overwrite' }),\n };\n}\n"]}
|
|
@@ -44,7 +44,7 @@ export function shouldExternalizePackage(params) {
|
|
|
44
44
|
(inlined?.length && inlined.includes(parseImportString(id).packageName)) ||
|
|
45
45
|
// A file outside of the package is doing this import, so we should inline the nested dependencies.
|
|
46
46
|
// Except if the dependency is listed as external.
|
|
47
|
-
(isNestedDependency(inputPath, parent) && !isExternalPackage));
|
|
47
|
+
(isNestedDependency(inputPath, parent) && !isExternalPackage && !isRelayArtifact(parent)));
|
|
48
48
|
}
|
|
49
49
|
function isInlinedNodeBuiltin(id, polyfills) {
|
|
50
50
|
return isBuiltin(id) || !!polyfills?.has(id);
|
|
@@ -60,4 +60,10 @@ function isNestedDependency(inputPath, parent) {
|
|
|
60
60
|
function isExternal(id, external) {
|
|
61
61
|
return !!external?.find((ex) => id.startsWith(ex));
|
|
62
62
|
}
|
|
63
|
+
// Check if the importer is an artifact as it might be in a grandparent directory.
|
|
64
|
+
// Rollup parent is the filename ../__generated__/foo.graphql.ts
|
|
65
|
+
// while webpack/rspack parent is the dirname ../__generated__/
|
|
66
|
+
function isRelayArtifact(parent) {
|
|
67
|
+
return !!parent?.includes('__generated__');
|
|
68
|
+
}
|
|
63
69
|
//# sourceMappingURL=shouldExternalizePackage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shouldExternalizePackage.js","sourceRoot":"","sources":["../src/shouldExternalizePackage.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC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AAC,EAAU;IAC5B,OAAO,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,GAAG,IAAI,EAAE,KAAK,IAAI,CAAC;AACxG,CAAC;AAED,wDAAwD;AACxD,SAAS,kBAAkB,CAAC,SAAiB,EAAE,MAA0B;IACvE,MAAM,kBAAkB,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACjF,OAAO,CAAC,CAAC,CAAC,kBAAkB,EAAE,UAAU,CAAC,IAAI,CAAC,IAAI,kBAAkB,EAAE,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC;AAClG,CAAC;AAED,SAAS,UAAU,CAAC,EAAU,EAAE,QAA8B;IAC5D,OAAO,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC;AACrD,CAAC;AAED,kFAAkF;AAClF,gEAAgE;AAChE,+DAA+D;AAC/D,SAAS,eAAe,CAAC,MAAe;IACtC,OAAO,CAAC,CAAC,MAAM,EAAE,QAAQ,CAAC,eAAe,CAAC,CAAC;AAC7C,CAAC","sourcesContent":["import type { BundleMode, TargetEnvironment } from '@ms-cloudpack/common-types';\nimport { parseImportString } from '@ms-cloudpack/path-string-parsing';\nimport { isBuiltin } from 'module';\nimport path from 'path';\n\nexport interface ShouldExternalizePackageOptions {\n /**\n * The absolute input path for the entry points to be bundled.\n */\n inputPath: string;\n /**\n * The module ID (import path) being evaluated for externalization.\n * This can be a package name or a relative/absolute path.\n */\n id: string;\n /**\n * The absolute file path of the module importing this dependency.\n * Used to determine if the import is coming from outside the package.\n * If it is undefined, the import is considered to be from the same package (this is common in Rollup).\n */\n parent?: string;\n /**\n * List of dependencies which should be explicitly inlined rather than externalized.\n * These will always be bundled with the package regardless of other settings.\n */\n inlined?: string[];\n /**\n * List of dependencies which should be explicitly externalized.\n * These will never be bundled with the package.\n */\n external?: string[];\n /**\n * Additional polyfill package names that should be inlined instead of externalized\n * if `shouldInlineNodeBuiltins` is true. This does NOT need to include Node.js built-ins.\n */\n polyfills?: Set<string>;\n /**\n * Whether Node.js built-in modules should be inlined (with polyfills) rather than externalized.\n * When true, modules like 'fs' or 'path' will be replaced with browser-compatible versions.\n *\n * If `targetEnvironment` is `'node'`, this will always be ignored since built-ins should always be externalized.\n */\n shouldInlineNodeBuiltins: boolean;\n /**\n * Where the bundled code will run.\n */\n targetEnvironment: TargetEnvironment;\n /**\n * Bundle mode. In production/development mode, all packages will be inlined, except Node built-ins if\n * `targetEnvironment` is `'node'`. (You can skip calling this function and just inline everything for\n * `targetEnvironment: 'browser'`.)\n */\n mode: BundleMode;\n}\n\n/**\n * Determines if a package should be externalized from the bundle.\n * Don't externalize inlined packages, node builtins, absolute paths, relative paths,\n * or dependencies of inlined dependencies except if they are explicitly marked as external.\n *\n * Example params (`<root>` is the absolute repo root path):\n * ```ts\n * {\n * inputPath: \"<root>/app\",\n * id: \"<root>/app/src/about.tsx\",\n * parent: \"<root>/app/src/index.tsx\",\n * inlined: [\"foo\"],\n * external: [\"bar\", \"baz\"],\n * polyfills: new Set([\"global\"]),\n * shouldInlineNodeBuiltins: false,\n * targetEnvironment: \"browser\",\n * mode: \"library\"\n * )\n * ```\n */\nexport function shouldExternalizePackage(params: ShouldExternalizePackageOptions): boolean {\n const { inputPath, id, parent, inlined, external, polyfills, shouldInlineNodeBuiltins, targetEnvironment, mode } =\n params;\n\n if (targetEnvironment === 'node' && isBuiltin(id)) {\n // For Node.js, always externalize built-in modules, even in production mode.\n return true;\n }\n\n if (mode !== 'library') {\n // For production/development mode, don't externalize anything (except as above).\n return false;\n }\n\n const isExternalPackage = isExternal(id, external);\n\n return !(\n (targetEnvironment === 'browser' &&\n // For browser bundles, we should inline node builtins that are handled by the nodePolyfills plugin.\n // Except if the dependency is listed as external.\n !isExternalPackage &&\n shouldInlineNodeBuiltins &&\n isInlinedNodeBuiltin(id, polyfills)) ||\n path.isAbsolute(id) ||\n isRelative(id) ||\n // The length check ensures that parseImportString is only called when there are inlined deps\n (inlined?.length && inlined.includes(parseImportString(id).packageName)) ||\n // A file outside of the package is doing this import, so we should inline the nested dependencies.\n // Except if the dependency is listed as external.\n (isNestedDependency(inputPath, parent) && !isExternalPackage && !isRelayArtifact(parent))\n );\n}\n\nfunction isInlinedNodeBuiltin(id: string, polyfills: Set<string> | undefined): boolean {\n return isBuiltin(id) || !!polyfills?.has(id);\n}\n\nfunction isRelative(id: string): boolean {\n return id.startsWith('/') || id.startsWith('./') || id.startsWith('../') || id === '.' || id === '..';\n}\n\n// Check if the import comes from an inlined dependency.\nfunction isNestedDependency(inputPath: string, parent: string | undefined): boolean {\n const relativeParentPath = parent ? path.relative(inputPath, parent) : undefined;\n return !!(relativeParentPath?.startsWith('..') || relativeParentPath?.includes('node_modules'));\n}\n\nfunction isExternal(id: string, external: string[] | undefined): boolean {\n return !!external?.find((ex) => id.startsWith(ex));\n}\n\n// Check if the importer is an artifact as it might be in a grandparent directory.\n// Rollup parent is the filename ../__generated__/foo.graphql.ts\n// while webpack/rspack parent is the dirname ../__generated__/\nfunction isRelayArtifact(parent?: string): boolean {\n return !!parent?.includes('__generated__');\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/bundler-utilities",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Utilities used by multiple Cloudpack bundlers implementations",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -15,14 +15,14 @@
|
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@ms-cloudpack/json-utilities": "^0.1.11",
|
|
18
|
-
"@ms-cloudpack/package-utilities": "^13.0.
|
|
18
|
+
"@ms-cloudpack/package-utilities": "^13.0.1",
|
|
19
19
|
"@ms-cloudpack/path-string-parsing": "^1.2.7",
|
|
20
|
-
"@ms-cloudpack/path-utilities": "^3.1.
|
|
20
|
+
"@ms-cloudpack/path-utilities": "^3.1.26",
|
|
21
21
|
"get-tsconfig": "^4.7.2",
|
|
22
22
|
"tsconfig-to-swcconfig": "^2.7.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@ms-cloudpack/common-types": "^0.
|
|
25
|
+
"@ms-cloudpack/common-types": "^0.29.0",
|
|
26
26
|
"@ms-cloudpack/eslint-plugin-internal": "^0.0.1",
|
|
27
27
|
"@ms-cloudpack/scripts": "^0.0.1",
|
|
28
28
|
"@ms-cloudpack/test-utilities": "^0.5.0",
|