@ms-cloudpack/bundler-utilities 0.1.1

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/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # @ms-cloudpack/bundler-utilities
2
+
3
+ Utilities used by multiple Cloudpack bundler implementations.
@@ -0,0 +1,3 @@
1
+ /** Default ES syntax level. 2022 is the minimum for top-level await. */
2
+ export declare const defaultTargetSyntax = "es2022";
3
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,eAAO,MAAM,mBAAmB,WAAW,CAAC"}
@@ -0,0 +1,3 @@
1
+ /** Default ES syntax level. 2022 is the minimum for top-level await. */
2
+ export const defaultTargetSyntax = 'es2022';
3
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,MAAM,CAAC,MAAM,mBAAmB,GAAG,QAAQ,CAAC","sourcesContent":["/** Default ES syntax level. 2022 is the minimum for top-level await. */\nexport const defaultTargetSyntax = 'es2022';\n"]}
@@ -0,0 +1,24 @@
1
+ import type { Config as SwcConfig } from '@swc/core';
2
+ interface GetSwcConfigParams {
3
+ /** Absolute path to the package (`inputPath`) */
4
+ packagePath: string;
5
+ /** Whether to generate sourcemaps */
6
+ sourcemap: boolean | undefined;
7
+ }
8
+ /**
9
+ * Gets the SWC configuration for a package, either from `.swcrc`(`.json`), by converting
10
+ * `tsconfig.json`, or using some basic default options.
11
+ *
12
+ * Notably, this will use a higher default target level than the default SWC config to reduce
13
+ * unnecessary downleveling, and override various options that are required for how cloudpack works.
14
+ *
15
+ * (Note that any unset options will use [swc defaults](https://swc.rs/docs/configuration/swcrc).)
16
+ *
17
+ * @returns JS and TS variants of the config, to avoid processing any config files twice.
18
+ */
19
+ export declare function getSwcConfig(params: GetSwcConfigParams): {
20
+ ts: SwcConfig;
21
+ js: SwcConfig;
22
+ };
23
+ export {};
24
+ //# sourceMappingURL=getSwcConfig.d.ts.map
@@ -0,0 +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;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,kBAAkB,GAAG;IAAE,EAAE,EAAE,SAAS,CAAC;IAAC,EAAE,EAAE,SAAS,CAAA;CAAE,CAkDzF"}
@@ -0,0 +1,77 @@
1
+ import { readJsonSync } from '@ms-cloudpack/json-utilities';
2
+ import { mergeObjects } from '@ms-cloudpack/package-utilities';
3
+ import fs from 'fs';
4
+ import { parseTsconfig } from 'get-tsconfig';
5
+ import path from 'path';
6
+ import { convertTsConfig } from 'tsconfig-to-swcconfig';
7
+ import { defaultTargetSyntax } from './constants.js';
8
+ /** Overrides all other configs */
9
+ const getUniversalConfig = (params) => ({
10
+ jsc: {
11
+ target: defaultTargetSyntax,
12
+ // We can't reference the separate @swc/helpers package from bundles
13
+ externalHelpers: false,
14
+ },
15
+ module: {
16
+ type: 'es6',
17
+ },
18
+ sourceMaps: params.sourcemap,
19
+ });
20
+ const jsParserConfig = { jsc: { parser: { syntax: 'ecmascript', jsx: true } } };
21
+ const tsParserConfig = { jsc: { parser: { syntax: 'typescript', tsx: true } } };
22
+ /**
23
+ * Gets the SWC configuration for a package, either from `.swcrc`(`.json`), by converting
24
+ * `tsconfig.json`, or using some basic default options.
25
+ *
26
+ * Notably, this will use a higher default target level than the default SWC config to reduce
27
+ * unnecessary downleveling, and override various options that are required for how cloudpack works.
28
+ *
29
+ * (Note that any unset options will use [swc defaults](https://swc.rs/docs/configuration/swcrc).)
30
+ *
31
+ * @returns JS and TS variants of the config, to avoid processing any config files twice.
32
+ */
33
+ export function getSwcConfig(params) {
34
+ const { packagePath } = params;
35
+ // First try reading .swcrc(.json).
36
+ // (It might have comments but doesn't have config extension, at least in v1.)
37
+ const swcrc = readJsonSync(path.join(packagePath, '.swcrc'), { mode: 'permissive' }) ||
38
+ readJsonSync(path.join(packagePath, '.swcrc.json'), { mode: 'permissive' });
39
+ let packageConfig;
40
+ // .swcrc can have either a single object or an array with `test`.
41
+ // Possibly we could add some logic to handle the array based on file extensions
42
+ // https://swc.rs/docs/configuration/compilation#multiple-entries
43
+ if (Array.isArray(swcrc)) {
44
+ console.warn(`Found array in .swcrc at ${packagePath} - this is not currently supported, so default settings will be used instead.`);
45
+ }
46
+ else if (swcrc) {
47
+ console.debug(`Found .swcrc at ${packagePath}`);
48
+ packageConfig = swcrc;
49
+ }
50
+ const tsconfigPath = path.join(packagePath, 'tsconfig.json');
51
+ if (!packageConfig && fs.existsSync(tsconfigPath)) {
52
+ // Read tsconfig.json from the package path if present, and convert it to swc config.
53
+ // (We use a separate read step instead of calling all-in-one tsconfig-to-swcconfig `convert()`
54
+ // because that searches up parent dirs for a tsconfig.json, which is worse for perf.)
55
+ try {
56
+ const tsconfig = parseTsconfig(tsconfigPath);
57
+ packageConfig = convertTsConfig(tsconfig.compilerOptions || {}, undefined, packagePath);
58
+ }
59
+ catch {
60
+ // ignore
61
+ }
62
+ }
63
+ const result = mergeObjects([packageConfig || {}, getUniversalConfig(params)], { arrayMerge: 'overwrite' });
64
+ // minifying should be up to the bundler
65
+ delete result.jsc?.minify;
66
+ // env conflicts with jsc.target -- currently we only use target
67
+ // https://swc.rs/docs/configuration/compilation#env
68
+ delete result.env;
69
+ // delete jsx/tsx options (will apply the correct one in the last step)
70
+ delete result.jsc?.parser?.tsx;
71
+ delete result.jsc?.parser?.jsx;
72
+ return {
73
+ js: mergeObjects([result, jsParserConfig], { arrayMerge: 'overwrite' }),
74
+ ts: mergeObjects([result, tsParserConfig], { arrayMerge: 'overwrite' }),
75
+ };
76
+ }
77
+ //# sourceMappingURL=getSwcConfig.js.map
@@ -0,0 +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,cAAc,GAAc,EAAE,GAAG,EAAE,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;AAC3F,MAAM,cAAc,GAAc,EAAE,GAAG,EAAE,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;AAE3F;;;;;;;;;;GAUG;AACH,MAAM,UAAU,YAAY,CAAC,MAA0B;IACrD,MAAM,EAAE,WAAW,EAAE,G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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,EAAE,EAAE,YAAY,CAAY,CAAC,MAAM,EAAE,cAAc,CAAC,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC;QAClF,EAAE,EAAE,YAAY,CAAY,CAAC,MAAM,EAAE,cAAc,CAAC,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC;KACnF,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 jsParserConfig: SwcConfig = { jsc: { parser: { syntax: 'ecmascript', jsx: true } } };\nconst tsParserConfig: 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 *\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 * (Note that any unset options will use [swc defaults](https://swc.rs/docs/configuration/swcrc).)\n *\n * @returns JS and TS variants of the config, to avoid processing any config files twice.\n */\nexport function getSwcConfig(params: GetSwcConfigParams): { ts: SwcConfig; js: SwcConfig } {\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 // 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 js: mergeObjects<SwcConfig>([result, jsParserConfig], { arrayMerge: 'overwrite' }),\n ts: mergeObjects<SwcConfig>([result, tsParserConfig], { arrayMerge: 'overwrite' }),\n };\n}\n"]}
package/lib/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export { defaultTargetSyntax } from './constants.js';
2
+ export { getSwcConfig } from './getSwcConfig.js';
3
+ export { shouldExternalizePackage } from './shouldExternalizePackage.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC"}
package/lib/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export { defaultTargetSyntax } from './constants.js';
2
+ export { getSwcConfig } from './getSwcConfig.js';
3
+ export { shouldExternalizePackage } from './shouldExternalizePackage.js';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC","sourcesContent":["export { defaultTargetSyntax } from './constants.js';\nexport { getSwcConfig } from './getSwcConfig.js';\nexport { shouldExternalizePackage } from './shouldExternalizePackage.js';\n"]}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Determines if a package should be externalized from the bundle.
3
+ * Don't externalize inlined packages, node builtins, absolute paths, or relative paths.
4
+ */
5
+ export declare function shouldExternalizePackage(params: {
6
+ id: string;
7
+ inlined?: string[];
8
+ external?: string[];
9
+ polyfills?: Set<string>;
10
+ shouldInlineNodeBuiltins: boolean;
11
+ }): boolean;
12
+ //# sourceMappingURL=shouldExternalizePackage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shouldExternalizePackage.d.ts","sourceRoot":"","sources":["../src/shouldExternalizePackage.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE;IAC/C,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,SAAS,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACxB,wBAAwB,EAAE,OAAO,CAAC;CACnC,GAAG,OAAO,CAUV"}
@@ -0,0 +1,24 @@
1
+ import { parseImportString } from '@ms-cloudpack/path-string-parsing';
2
+ import { isBuiltin } from 'module';
3
+ import path from 'path';
4
+ /**
5
+ * Determines if a package should be externalized from the bundle.
6
+ * Don't externalize inlined packages, node builtins, absolute paths, or relative paths.
7
+ */
8
+ export function shouldExternalizePackage(params) {
9
+ const { id, inlined, external, polyfills, shouldInlineNodeBuiltins } = params;
10
+ return !((shouldInlineNodeBuiltins && isInlinedNodeBuiltin(id, external, polyfills)) ||
11
+ path.isAbsolute(id) ||
12
+ isRelative(id) ||
13
+ // The length check ensures that parseImportString is only called when there are inlined deps
14
+ (inlined?.length && inlined.includes(parseImportString(id).packageName)));
15
+ }
16
+ // We should inline node builtins that are handled by the nodePolyfills plugin.
17
+ // Except if the dependency is listed as external.
18
+ function isInlinedNodeBuiltin(id, external, polyfills) {
19
+ return (isBuiltin(id) || polyfills?.has(id)) && !external?.find((ex) => id.startsWith(ex));
20
+ }
21
+ function isRelative(id) {
22
+ return id.startsWith('/') || id.startsWith('./') || id.startsWith('../') || id === '.' || id === '..';
23
+ }
24
+ //# sourceMappingURL=shouldExternalizePackage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shouldExternalizePack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ms-cloudpack/path-string-parsing';\nimport { isBuiltin } from 'module';\nimport path from 'path';\n\n/**\n * Determines if a package should be externalized from the bundle.\n * Don't externalize inlined packages, node builtins, absolute paths, or relative paths.\n */\nexport function shouldExternalizePackage(params: {\n id: string;\n inlined?: string[];\n external?: string[];\n polyfills?: Set<string>;\n shouldInlineNodeBuiltins: boolean;\n}): boolean {\n const { id, inlined, external, polyfills, shouldInlineNodeBuiltins } = params;\n\n return !(\n (shouldInlineNodeBuiltins && isInlinedNodeBuiltin(id, external, 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 );\n}\n\n// We should inline node builtins that are handled by the nodePolyfills plugin.\n// Except if the dependency is listed as external.\nfunction isInlinedNodeBuiltin(id: string, external: string[] | undefined, polyfills: Set<string> | undefined) {\n return (isBuiltin(id) || polyfills?.has(id)) && !external?.find((ex) => id.startsWith(ex));\n}\n\nfunction isRelative(id: string) {\n return id.startsWith('/') || id.startsWith('./') || id.startsWith('../') || id === '.' || id === '..';\n}\n"]}
@@ -0,0 +1,11 @@
1
+ // This file is read by tools that parse documentation comments conforming to the TSDoc standard.
2
+ // It should be published with your NPM package. It should not be tracked by Git.
3
+ {
4
+ "tsdocVersion": "0.12",
5
+ "toolPackages": [
6
+ {
7
+ "packageName": "@microsoft/api-extractor",
8
+ "packageVersion": "7.47.9"
9
+ }
10
+ ]
11
+ }
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@ms-cloudpack/bundler-utilities",
3
+ "version": "0.1.1",
4
+ "description": "Utilities used by multiple bundlers.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "types": "./lib/index.d.ts",
8
+ "sideEffects": false,
9
+ "exports": {
10
+ ".": {
11
+ "source": "./src/index.ts",
12
+ "types": "./lib/index.d.ts",
13
+ "import": "./lib/index.js"
14
+ }
15
+ },
16
+ "dependencies": {
17
+ "@ms-cloudpack/json-utilities": "^0.1.7",
18
+ "@ms-cloudpack/package-utilities": "^10.2.1",
19
+ "@ms-cloudpack/path-string-parsing": "^1.2.4",
20
+ "get-tsconfig": "^4.7.2",
21
+ "tsconfig-to-swcconfig": "^2.7.0"
22
+ },
23
+ "devDependencies": {
24
+ "@ms-cloudpack/eslint-plugin-internal": "^0.0.1",
25
+ "@ms-cloudpack/scripts": "^0.0.1",
26
+ "@ms-cloudpack/test-utilities": "^0.5.0",
27
+ "@swc/core": "^1.3.0"
28
+ },
29
+ "scripts": {
30
+ "api": "cloudpack-scripts api",
31
+ "build:watch": "cloudpack-scripts build-watch",
32
+ "build": "cloudpack-scripts build",
33
+ "lint:update": "cloudpack-scripts lint-update",
34
+ "lint": "cloudpack-scripts lint",
35
+ "test:update": "cloudpack-scripts test-update",
36
+ "test:watch": "cloudpack-scripts test-watch",
37
+ "test": "cloudpack-scripts test"
38
+ },
39
+ "files": [
40
+ "lib/**/!(*.test.*)"
41
+ ]
42
+ }