@ms-cloudpack/bundler-utilities 0.8.0 → 0.9.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.
@@ -4,6 +4,8 @@ interface GetSwcConfigParams {
4
4
  packagePath: string;
5
5
  /** Whether to generate sourcemaps */
6
6
  sourcemap: boolean | undefined;
7
+ /** Enable React Refresh transform (for development HMR) */
8
+ reactRefresh: boolean | undefined;
7
9
  }
8
10
  /**
9
11
  * Gets the SWC configuration for a package, either from `.swcrc`(`.json`), by converting
@@ -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,CA4DA"}
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;IAC/B,2DAA2D;IAC3D,YAAY,EAAE,OAAO,GAAG,SAAS,CAAC;CACnC;AAqCD;;;;;;;;;;;;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"}
@@ -11,6 +11,24 @@ const getUniversalConfig = (params) => ({
11
11
  target: defaultTargetSyntax,
12
12
  // We can't reference the separate @swc/helpers package from bundles
13
13
  externalHelpers: false,
14
+ // Add React Refresh transform configuration when enabled
15
+ // This is used for Hot Module Replacement (HMR) in development
16
+ ...(params.reactRefresh && {
17
+ transform: {
18
+ react: {
19
+ // Enables React Refresh (Fast Refresh) by injecting runtime code
20
+ // This transforms React components to be "hot reloadable" by:
21
+ // 1. Adding $RefreshReg$ calls to register each component
22
+ // 2. Adding $RefreshSig$ calls to track hook signatures
23
+ // 3. Wrapping exports to enable re-execution when code changes
24
+ // Without this, components would require full page reloads on every change
25
+ refresh: true,
26
+ // REQUIRED prerequisite for React Refresh to work
27
+ // React Refresh will not function without this setting enabled
28
+ development: true,
29
+ },
30
+ },
31
+ }),
14
32
  },
15
33
  module: {
16
34
  type: 'es6',
@@ -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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AAE,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"]}
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;AAWrD,kCAAkC;AAClC,MAAM,kBAAkB,GAAG,CAAC,MAA8D,EAAa,EAAE,CAAC,CAAC;IACzG,GAAG,EAAE;QACH,MAAM,EAAE,mBAAmB;QAC3B,oEAAoE;QACpE,eAAe,EAAE,KAAK;QACtB,yDAAyD;QACzD,+DAA+D;QAC/D,GAAG,CAAC,MAAM,CAAC,YAAY,IAAI;YACzB,SAAS,EAAE;gBACT,KAAK,EAAE;oBACL,iEAAiE;oBACjE,8DAA8D;oBAC9D,0DAA0D;oBAC1D,wDAAwD;oBACxD,+DAA+D;oBAC/D,2EAA2E;oBAC3E,OAAO,EAAE,IAAI;oBAEb,kDAAkD;oBAClD,+DAA+D;oBAC/D,WAAW,EAAE,IAAI;iBAClB;aACF;SACF,CAAC;KACH;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,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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 /** Enable React Refresh transform (for development HMR) */\n reactRefresh: boolean | undefined;\n}\n\n/** Overrides all other configs */\nconst getUniversalConfig = (params: Pick<GetSwcConfigParams, 'sourcemap' | 'reactRefresh'>): SwcConfig => ({\n jsc: {\n target: defaultTargetSyntax,\n // We can't reference the separate @swc/helpers package from bundles\n externalHelpers: false,\n // Add React Refresh transform configuration when enabled\n // This is used for Hot Module Replacement (HMR) in development\n ...(params.reactRefresh && {\n transform: {\n react: {\n // Enables React Refresh (Fast Refresh) by injecting runtime code\n // This transforms React components to be \"hot reloadable\" by:\n // 1. Adding $RefreshReg$ calls to register each component\n // 2. Adding $RefreshSig$ calls to track hook signatures\n // 3. Wrapping exports to enable re-execution when code changes\n // Without this, components would require full page reloads on every change\n refresh: true,\n\n // REQUIRED prerequisite for React Refresh to work\n // React Refresh will not function without this setting enabled\n development: true,\n },\n },\n }),\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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/bundler-utilities",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "Utilities used by multiple Cloudpack bundlers implementations",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -25,14 +25,14 @@
25
25
  },
26
26
  "dependencies": {
27
27
  "@ms-cloudpack/json-utilities": "^0.1.11",
28
- "@ms-cloudpack/package-utilities": "^13.2.5",
29
- "@ms-cloudpack/path-string-parsing": "^1.2.7",
30
- "@ms-cloudpack/path-utilities": "^3.2.2",
28
+ "@ms-cloudpack/package-utilities": "^13.2.6",
29
+ "@ms-cloudpack/path-string-parsing": "^1.3.0",
30
+ "@ms-cloudpack/path-utilities": "^3.2.3",
31
31
  "get-tsconfig": "^4.7.2",
32
32
  "tsconfig-to-swcconfig": "^2.7.0"
33
33
  },
34
34
  "devDependencies": {
35
- "@ms-cloudpack/common-types": "^0.33.1",
35
+ "@ms-cloudpack/common-types": "^0.33.2",
36
36
  "@ms-cloudpack/eslint-plugin-internal": "^0.0.1",
37
37
  "@ms-cloudpack/scripts": "^0.0.1",
38
38
  "@ms-cloudpack/test-utilities": "^0.5.0",