@granite-js/mpack 1.0.26 → 1.0.27

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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @granite-js/mpack
2
2
 
3
+ ## 1.0.27
4
+
5
+ ### Patch Changes
6
+
7
+ - @granite-js/plugin-core@1.0.27
8
+ - @granite-js/utils@1.0.27
9
+
3
10
  ## 1.0.26
4
11
 
5
12
  ### Patch Changes
@@ -1,8 +1,11 @@
1
1
  import * as babel from '@babel/core';
2
+ import type { BuildConfig } from '@granite-js/plugin-core';
2
3
  import { AsyncTransformStep } from '../../../../transformer/TransformPipeline';
3
4
  interface FullyTransformStepConfig {
4
5
  dev: boolean;
6
+ platform: string;
5
7
  additionalBabelOptions?: babel.TransformOptions;
8
+ INTERNAL__babelOptions?: BuildConfig['INTERNAL__babelOptions'];
6
9
  }
7
- export declare function createFullyTransformStep({ dev, additionalBabelOptions, }: FullyTransformStepConfig): AsyncTransformStep;
10
+ export declare function createFullyTransformStep({ dev, platform, additionalBabelOptions, INTERNAL__babelOptions, }: FullyTransformStepConfig): AsyncTransformStep;
8
11
  export {};
@@ -36,7 +36,9 @@ var babel = __toESM(require("@babel/core"));
36
36
  var import_defineStepName = require("../../../../utils/defineStepName");
37
37
  function createFullyTransformStep({
38
38
  dev,
39
- additionalBabelOptions
39
+ platform,
40
+ additionalBabelOptions,
41
+ INTERNAL__babelOptions
40
42
  }) {
41
43
  const baseOptions = {
42
44
  configFile: additionalBabelOptions?.configFile || false,
@@ -84,7 +86,7 @@ function createFullyTransformStep({
84
86
  ]
85
87
  };
86
88
  const fullyTransformStep = async function fullyTransform(code, args) {
87
- const babelOptions = babel.loadOptions({
89
+ const babelOptions = {
88
90
  minified: false,
89
91
  compact: false,
90
92
  babelrc: false,
@@ -97,14 +99,17 @@ function createFullyTransformStep({
97
99
  name: "mpack-fully-transform-plugin",
98
100
  supportsStaticESM: true
99
101
  }
100
- });
101
- if (!babelOptions) {
102
+ };
103
+ const resolvedBabelOptions = babel.loadOptions(
104
+ INTERNAL__babelOptions ? await INTERNAL__babelOptions({ platform, dev }, babelOptions) : babelOptions
105
+ );
106
+ if (!resolvedBabelOptions) {
102
107
  return { code };
103
108
  }
104
- if (babelOptions.sourceMaps) {
105
- babelOptions.sourceFileName = path.basename(args.path);
109
+ if (resolvedBabelOptions.sourceMaps) {
110
+ resolvedBabelOptions.sourceFileName = path.basename(args.path);
106
111
  }
107
- const result = await babel.transformAsync(code, babelOptions);
112
+ const result = await babel.transformAsync(code, resolvedBabelOptions);
108
113
  if (result?.code != null) {
109
114
  return { code: result.code };
110
115
  }
@@ -2,6 +2,8 @@ import type { BuildConfig } from '@granite-js/plugin-core';
2
2
  import { AsyncTransformStep } from '../../../../transformer/TransformPipeline';
3
3
  export interface TransformToHermesSyntaxStepConfig {
4
4
  dev: boolean;
5
+ platform: string;
5
6
  additionalSwcOptions?: BuildConfig['swc'];
7
+ INTERNAL__swcOptions?: BuildConfig['INTERNAL__swcOptions'];
6
8
  }
7
- export declare function createTransformToHermesSyntaxStep({ dev, additionalSwcOptions, }: TransformToHermesSyntaxStepConfig): AsyncTransformStep;
9
+ export declare function createTransformToHermesSyntaxStep({ dev, platform, additionalSwcOptions, INTERNAL__swcOptions, }: TransformToHermesSyntaxStepConfig): AsyncTransformStep;
@@ -38,7 +38,9 @@ var import_defineStepName = require("../../../../utils/defineStepName");
38
38
  var import_swc = require("../../shared/swc");
39
39
  function createTransformToHermesSyntaxStep({
40
40
  dev,
41
- additionalSwcOptions = {}
41
+ platform,
42
+ additionalSwcOptions = {},
43
+ INTERNAL__swcOptions
42
44
  }) {
43
45
  const plugins = (additionalSwcOptions.plugins ?? []).filter(import_es_toolkit.isNotNil);
44
46
  const transformToHermesSyntaxStep = async function transformToHermesSyntax(code, args) {
@@ -74,7 +76,8 @@ function createTransformToHermesSyntaxStep({
74
76
  sourceMaps: "inline",
75
77
  filename: import_path.default.basename(args.path)
76
78
  };
77
- const result = await swc.transform(code, options);
79
+ const resolvedOptions = INTERNAL__swcOptions ? await INTERNAL__swcOptions({ platform, dev }, options) : options;
80
+ const result = await swc.transform(code, resolvedOptions);
78
81
  return { code: result.code };
79
82
  };
80
83
  (0, import_defineStepName.defineStepName)(transformToHermesSyntaxStep, "hermes-syntax");
@@ -48,7 +48,7 @@ function transformPlugin({ context, ...options }) {
48
48
  setup(build) {
49
49
  const { id, config } = context;
50
50
  const { dev, cache, buildConfig } = config;
51
- const { esbuild, swc, babel } = buildConfig;
51
+ const { esbuild, swc, babel, platform } = buildConfig;
52
52
  (0, import_assert.default)(id, "id \uAC12\uC774 \uC874\uC7AC\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4");
53
53
  (0, import_assert.default)(typeof dev === "boolean", "dev \uAC12\uC774 \uC874\uC7AC\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4");
54
54
  (0, import_assert.default)(typeof cache === "boolean", "cache \uAC12\uC774 \uC874\uC7AC\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4");
@@ -63,13 +63,25 @@ function transformPlugin({ context, ...options }) {
63
63
  return { code };
64
64
  }).addStep({
65
65
  if: ({ path, code }) => babel?.conditions?.some((cond) => cond(code, path)) ?? false,
66
- then: (0, import_createFullyTransformStep.createFullyTransformStep)({ dev, additionalBabelOptions: babel }),
66
+ then: (0, import_createFullyTransformStep.createFullyTransformStep)({
67
+ dev,
68
+ platform,
69
+ additionalBabelOptions: babel,
70
+ INTERNAL__babelOptions: buildConfig.INTERNAL__babelOptions
71
+ }),
67
72
  stopAfter: true
68
73
  }).addStep({
69
74
  if: ({ path }) => /(?:^|[\\/])(?:Native\w+|(\w+)NativeComponent)\.[jt]sx?$/.test(path),
70
75
  then: (0, import_createTransformCodegenStep.createTransformCodegenStep)(),
71
76
  else: (0, import_createFlowStripStep.createFlowStripStep)()
72
- }).addStep((0, import_createTransformToHermesSyntaxStep.createTransformToHermesSyntaxStep)({ dev, additionalSwcOptions: swc })).afterStep(cacheSteps.afterTransform);
77
+ }).addStep(
78
+ (0, import_createTransformToHermesSyntaxStep.createTransformToHermesSyntaxStep)({
79
+ dev,
80
+ platform,
81
+ additionalSwcOptions: swc,
82
+ INTERNAL__swcOptions: buildConfig.INTERNAL__swcOptions
83
+ })
84
+ ).afterStep(cacheSteps.afterTransform);
73
85
  preludeScript.registerEntryPointMarker(build);
74
86
  preludeScript.registerPreludeScriptResolver(build);
75
87
  build.onLoad({ filter: sourceRegExp }, async (args) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@granite-js/mpack",
3
- "version": "1.0.26",
3
+ "version": "1.0.27",
4
4
  "description": "A bundler for Granite apps",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -92,8 +92,8 @@
92
92
  "@babel/traverse": "7.28.5",
93
93
  "@babel/types": "7.28.5",
94
94
  "@fastify/middie": "8.3.0",
95
- "@granite-js/plugin-core": "1.0.26",
96
- "@granite-js/utils": "1.0.26",
95
+ "@granite-js/plugin-core": "1.0.27",
96
+ "@granite-js/utils": "1.0.27",
97
97
  "@react-native-community/cli-plugin-metro": "11.3.7",
98
98
  "@react-native-community/cli-server-api": "11.3.7",
99
99
  "@react-native-community/cli-tools": "11.3.7",