@ms-cloudpack/bundler-utilities 0.1.25 → 0.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.
@@ -14,11 +14,16 @@ interface GetSwcConfigParams {
14
14
  *
15
15
  * (Note that any unset options will use [swc defaults](https://swc.rs/docs/configuration/swcrc).)
16
16
  *
17
- * @returns JS and TS variants of the config, to avoid processing any config files twice.
17
+ * @returns JS/TS(X) variants of the config, to avoid processing any config files twice.
18
+ * (Properties are getters which do the appropriate merging on demand.)
18
19
  */
19
20
  export declare function getSwcConfig(params: GetSwcConfigParams): {
20
- ts: SwcConfig;
21
- js: SwcConfig;
21
+ /** Config for `.js` and `.jsx` files */
22
+ get jsx(): SwcConfig;
23
+ /** Config for `.ts` files (no TSX support) */
24
+ get tsOnly(): SwcConfig;
25
+ /** Config for `.tsx` files */
26
+ get tsx(): SwcConfig;
22
27
  };
23
28
  export {};
24
29
  //# sourceMappingURL=getSwcConfig.d.ts.map
@@ -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;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,kBAAkB,GAAG;IAAE,EAAE,EAAE,SAAS,CAAC;IAAC,EAAE,EAAE,SAAS,CAAA;CAAE,CA0DzF"}
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;AAmBD;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,kBAAkB,GAAG;IACxD,wCAAwC;IAExC,IAAI,GAAG,IAAI,SAAS,CAAC;IACrB,8CAA8C;IAC9C,IAAI,MAAM,IAAI,SAAS,CAAC;IACxB,8BAA8B;IAC9B,IAAI,GAAG,IAAI,SAAS,CAAC;CACtB,CAiEA"}
@@ -17,8 +17,9 @@ const getUniversalConfig = (params) => ({
17
17
  },
18
18
  sourceMaps: params.sourcemap,
19
19
  });
20
- const jsParserConfig = { jsc: { parser: { syntax: 'ecmascript', jsx: true } } };
21
- const tsParserConfig = { jsc: { parser: { syntax: 'typescript', tsx: true } } };
20
+ const jsxParserConfig = { jsc: { parser: { syntax: 'ecmascript', jsx: true } } };
21
+ const tsxParserConfig = { jsc: { parser: { syntax: 'typescript', tsx: true } } };
22
+ const tsOnlyParserConfig = { jsc: { parser: { syntax: 'typescript', tsx: false } } };
22
23
  /**
23
24
  * Gets the SWC configuration for a package, either from `.swcrc`(`.json`), by converting
24
25
  * `tsconfig.json`, or using some basic default options.
@@ -28,7 +29,8 @@ const tsParserConfig = { jsc: { parser: { syntax: 'typescript', tsx: true } } };
28
29
  *
29
30
  * (Note that any unset options will use [swc defaults](https://swc.rs/docs/configuration/swcrc).)
30
31
  *
31
- * @returns JS and TS variants of the config, to avoid processing any config files twice.
32
+ * @returns JS/TS(X) variants of the config, to avoid processing any config files twice.
33
+ * (Properties are getters which do the appropriate merging on demand.)
32
34
  */
33
35
  export function getSwcConfig(params) {
34
36
  const { packagePath } = params;
@@ -77,8 +79,15 @@ export function getSwcConfig(params) {
77
79
  delete result.jsc?.parser?.tsx;
78
80
  delete result.jsc?.parser?.jsx;
79
81
  return {
80
- js: mergeObjects([result, jsParserConfig], { arrayMerge: 'overwrite' }),
81
- ts: mergeObjects([result, tsParserConfig], { arrayMerge: 'overwrite' }),
82
+ get jsx() {
83
+ return mergeObjects([result, jsxParserConfig], { arrayMerge: 'overwrite' });
84
+ },
85
+ get tsx() {
86
+ return mergeObjects([result, tsxParserConfig], { arrayMerge: 'overwrite' });
87
+ },
88
+ get tsOnly() {
89
+ return mergeObjects([result, tsOnlyParserConfig], { arrayMerge: 'overwrite' });
90
+ },
82
91
  };
83
92
  }
84
93
  //# sourceMappingURL=getSwcConfig.js.map
@@ -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,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,E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aAAa,IAAI,EAAE,EAAE,kBAAkB,CAAC,MAAM,CAAC,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,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 /**\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 js: mergeObjects<SwcConfig>([result, jsParserConfig], { arrayMerge: 'overwrite' }),\n ts: mergeObjects<SwcConfig>([result, tsParserConfig], { 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,CAAC,MAA6C,EAAa,EAAE,CAAC,CAAC;IACxF,GAAG,EAAE;QACH,MAAM,E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OAAO,YAAY,CAAC,CAAC,MAAM,EAAE,eAAe,CAAC,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC,CAAC;QAC9E,CAAC;QACD,IAAI,GAAG;YACL,OAAO,YAAY,CAAC,CAAC,MAAM,EAAE,eAAe,CAAC,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC,CAAC;QAC9E,CAAC;QACD,IAAI,MAAM;YACR,OAAO,YAAY,CAAC,CAAC,MAAM,EAAE,kBAAkB,CAAC,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC,CAAC;QACjF,CAAC;KACF,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 } } };\nconst tsOnlyParserConfig: SwcConfig = { jsc: { parser: { syntax: 'typescript', tsx: false } } };\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/TS(X) variants of the config, to avoid processing any config files twice.\n * (Properties are getters which do the appropriate merging on demand.)\n */\nexport function getSwcConfig(params: GetSwcConfigParams): {\n /** Config for `.js` and `.jsx` files */\n // A JS-only variant could be added if needed\n get jsx(): SwcConfig;\n /** Config for `.ts` files (no TSX support) */\n get tsOnly(): SwcConfig;\n /** Config for `.tsx` files */\n get 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 get jsx() {\n return mergeObjects([result, jsxParserConfig], { arrayMerge: 'overwrite' });\n },\n get tsx() {\n return mergeObjects([result, tsxParserConfig], { arrayMerge: 'overwrite' });\n },\n get tsOnly() {\n return mergeObjects([result, tsOnlyParserConfig], { arrayMerge: 'overwrite' });\n },\n };\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/bundler-utilities",
3
- "version": "0.1.25",
3
+ "version": "0.2.0",
4
4
  "description": "Utilities used by multiple bundlers.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -15,9 +15,9 @@
15
15
  },
16
16
  "dependencies": {
17
17
  "@ms-cloudpack/json-utilities": "^0.1.10",
18
- "@ms-cloudpack/package-utilities": "^11.3.2",
18
+ "@ms-cloudpack/package-utilities": "^11.3.3",
19
19
  "@ms-cloudpack/path-string-parsing": "^1.2.6",
20
- "@ms-cloudpack/path-utilities": "^3.0.2",
20
+ "@ms-cloudpack/path-utilities": "^3.0.3",
21
21
  "get-tsconfig": "^4.7.2",
22
22
  "tsconfig-to-swcconfig": "^2.7.0"
23
23
  },