@granite-js/mpack 1.0.25 → 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 +18 -0
- package/dist/bundler/Bundler.js +7 -4
- package/dist/bundler/plugins/resolvePlugin/alias/setupAliasResolver.js +67 -13
- package/dist/bundler/plugins/transformPlugin/steps/createFullyTransformStep.d.ts +4 -1
- package/dist/bundler/plugins/transformPlugin/steps/createFullyTransformStep.js +12 -7
- package/dist/bundler/plugins/transformPlugin/steps/createTransformToHermesSyntaxStep.d.ts +3 -1
- package/dist/bundler/plugins/transformPlugin/steps/createTransformToHermesSyntaxStep.js +5 -2
- package/dist/bundler/plugins/transformPlugin/transformPlugin.js +15 -3
- package/dist/testing/buildWithEsbuild.d.ts +4 -1
- package/package.json +3 -3
- package/src/bundler/plugins/resolvePlugin/__tests__/fixtures/resolver-results/foo.d.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
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
|
+
|
|
10
|
+
## 1.0.26
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- b50c12f: propagate esbuild resolve result options in alias resolver
|
|
15
|
+
- 4acc9d6: Add INTERNAL\_\_esbuildOptions to allow dynamic configuration of esbuild build options.
|
|
16
|
+
- Updated dependencies [b50c12f]
|
|
17
|
+
- Updated dependencies [4acc9d6]
|
|
18
|
+
- @granite-js/plugin-core@1.0.26
|
|
19
|
+
- @granite-js/utils@1.0.26
|
|
20
|
+
|
|
3
21
|
## 1.0.25
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/dist/bundler/Bundler.js
CHANGED
|
@@ -66,7 +66,8 @@ class Bundler {
|
|
|
66
66
|
async build(options) {
|
|
67
67
|
const { withDispose = true } = options ?? {};
|
|
68
68
|
if (this.esbuildContext == null) {
|
|
69
|
-
|
|
69
|
+
const buildOptions = await this.getBaseBuildOptions();
|
|
70
|
+
this.esbuildContext = await esbuild.context(buildOptions);
|
|
70
71
|
}
|
|
71
72
|
if (this.status === "prepared" || this.status === "building") {
|
|
72
73
|
this.bundleTask?.abort();
|
|
@@ -97,8 +98,8 @@ ${error.stack ?? error.message}`);
|
|
|
97
98
|
process.exit(1);
|
|
98
99
|
});
|
|
99
100
|
}
|
|
100
|
-
getBaseBuildOptions() {
|
|
101
|
-
const { rootDir, metafile, buildConfig } = this.config;
|
|
101
|
+
async getBaseBuildOptions() {
|
|
102
|
+
const { rootDir, metafile, dev, buildConfig } = this.config;
|
|
102
103
|
const { platform, entry, outfile = "bundle.js", esbuild: esbuild2 = {} } = buildConfig;
|
|
103
104
|
const { prelude: _, ...esbuildOptions } = esbuild2;
|
|
104
105
|
const platforms = [platform, "native", "react-native"];
|
|
@@ -109,7 +110,7 @@ ${error.stack ?? error.message}`);
|
|
|
109
110
|
...supportedExtensions
|
|
110
111
|
].flat();
|
|
111
112
|
this.setupEnvironment();
|
|
112
|
-
|
|
113
|
+
const baseBuildOptions = {
|
|
113
114
|
entryPoints: [path.resolve(rootDir, entry)],
|
|
114
115
|
outfile: path.resolve(rootDir, outfile),
|
|
115
116
|
sourcemap: true,
|
|
@@ -165,6 +166,8 @@ ${error.stack ?? error.message}`);
|
|
|
165
166
|
...esbuildOptions?.plugins ?? []
|
|
166
167
|
].filter(import_es_toolkit.isNotNil)
|
|
167
168
|
};
|
|
169
|
+
const buildOptions = buildConfig.INTERNAL__esbuildOptions ? await buildConfig.INTERNAL__esbuildOptions({ dev, platform }, baseBuildOptions) : baseBuildOptions;
|
|
170
|
+
return buildOptions;
|
|
168
171
|
}
|
|
169
172
|
setupEnvironment() {
|
|
170
173
|
const envString = this.config.dev ?? true ? "development" : "production";
|
|
@@ -50,15 +50,9 @@ function setupAliasResolver(build, aliasConfig) {
|
|
|
50
50
|
const trace = import_performance.Performance.trace("alias-resolver", {
|
|
51
51
|
detail: { pattern: filter, path: args.path }
|
|
52
52
|
});
|
|
53
|
-
const defaultResolveOptions = {
|
|
54
|
-
resolveDir: args.resolveDir,
|
|
55
|
-
importer: args.importer,
|
|
56
|
-
kind: args.kind,
|
|
57
|
-
with: args.with
|
|
58
|
-
};
|
|
59
53
|
const resolveResult = await resolveAlias(args);
|
|
60
54
|
const resolvePath = resolveResult.path;
|
|
61
|
-
const resolveOptions =
|
|
55
|
+
const resolveOptions = toResolveOptions(args, resolveResult);
|
|
62
56
|
const cacheKey = `${resolveOptions.kind}:${resolveOptions.resolveDir}:${resolvePath}`;
|
|
63
57
|
if (resolveResultCache.has(cacheKey)) {
|
|
64
58
|
trace.stop({ detail: { cacheHit: true } });
|
|
@@ -67,13 +61,23 @@ function setupAliasResolver(build, aliasConfig) {
|
|
|
67
61
|
if (import_path.default.isAbsolute(resolvePath)) {
|
|
68
62
|
trace.stop({ detail: { isAbsolute: true } });
|
|
69
63
|
const result2 = { path: resolvePath };
|
|
64
|
+
applyOnResolveResultOptions(result2, resolveResult);
|
|
70
65
|
resolveResultCache.set(cacheKey, result2);
|
|
71
66
|
return result2;
|
|
72
67
|
}
|
|
73
|
-
const pathOverriddenArgs = {
|
|
68
|
+
const pathOverriddenArgs = {
|
|
69
|
+
path: resolvePath,
|
|
70
|
+
importer: args.importer,
|
|
71
|
+
namespace: args.namespace,
|
|
72
|
+
resolveDir: args.resolveDir,
|
|
73
|
+
kind: args.kind,
|
|
74
|
+
pluginData: args.pluginData,
|
|
75
|
+
with: args.with
|
|
76
|
+
};
|
|
74
77
|
const result = await resolver(pathOverriddenArgs, resolveOptions);
|
|
75
78
|
if (result) {
|
|
76
79
|
trace.stop({ detail: { cacheHit: false, isAbsolute: false } });
|
|
80
|
+
applyOnResolveResultOptions(result, resolveResult);
|
|
77
81
|
resolveResultCache.set(cacheKey, result);
|
|
78
82
|
return result;
|
|
79
83
|
}
|
|
@@ -86,8 +90,19 @@ function resolveAliasConfig(build, aliasConfig) {
|
|
|
86
90
|
const escapedFrom = escapeRegExpString(from);
|
|
87
91
|
const filter = new RegExp(exact ? `^${escapedFrom}$` : `^${escapedFrom}(?:$|/)`);
|
|
88
92
|
const resolver = (0, import_resolveHelpers.createNonRecursiveResolver)(build);
|
|
89
|
-
const aliasResolver = (
|
|
90
|
-
const result = resolver(
|
|
93
|
+
const aliasResolver = (args, path2, options) => {
|
|
94
|
+
const result = resolver(
|
|
95
|
+
{
|
|
96
|
+
path: path2,
|
|
97
|
+
importer: args.importer,
|
|
98
|
+
namespace: args.namespace,
|
|
99
|
+
resolveDir: args.resolveDir,
|
|
100
|
+
kind: args.kind,
|
|
101
|
+
pluginData: args.pluginData,
|
|
102
|
+
with: args.with
|
|
103
|
+
},
|
|
104
|
+
options
|
|
105
|
+
);
|
|
91
106
|
(0, import_es_toolkit.assert)(result, "resolver should return result");
|
|
92
107
|
return result;
|
|
93
108
|
};
|
|
@@ -108,10 +123,49 @@ function escapeRegExpString(str) {
|
|
|
108
123
|
}
|
|
109
124
|
function normalizeResolveResult(result) {
|
|
110
125
|
if (typeof result === "string") {
|
|
111
|
-
return { path: (0, import_esbuildUtils.normalizePath)(result)
|
|
126
|
+
return { path: (0, import_esbuildUtils.normalizePath)(result) };
|
|
127
|
+
}
|
|
128
|
+
return result;
|
|
129
|
+
}
|
|
130
|
+
function toResolveOptions(args, result) {
|
|
131
|
+
return {
|
|
132
|
+
resolveDir: result.resolveDir ?? args.resolveDir,
|
|
133
|
+
importer: result.importer ?? args.importer,
|
|
134
|
+
kind: result.kind ?? args.kind,
|
|
135
|
+
with: result.with ?? args.with
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
function applyOnResolveResultOptions(target, source) {
|
|
139
|
+
if (source.pluginName !== void 0) {
|
|
140
|
+
target.pluginName = source.pluginName;
|
|
141
|
+
}
|
|
142
|
+
if (source.errors !== void 0) {
|
|
143
|
+
target.errors = source.errors;
|
|
144
|
+
}
|
|
145
|
+
if (source.warnings !== void 0) {
|
|
146
|
+
target.warnings = source.warnings;
|
|
147
|
+
}
|
|
148
|
+
if (source.external !== void 0) {
|
|
149
|
+
target.external = source.external;
|
|
150
|
+
}
|
|
151
|
+
if (source.sideEffects !== void 0) {
|
|
152
|
+
target.sideEffects = source.sideEffects;
|
|
153
|
+
}
|
|
154
|
+
if (source.namespace !== void 0) {
|
|
155
|
+
target.namespace = source.namespace;
|
|
156
|
+
}
|
|
157
|
+
if (source.suffix !== void 0) {
|
|
158
|
+
target.suffix = source.suffix;
|
|
159
|
+
}
|
|
160
|
+
if (source.pluginData !== void 0) {
|
|
161
|
+
target.pluginData = source.pluginData;
|
|
162
|
+
}
|
|
163
|
+
if (source.watchFiles !== void 0) {
|
|
164
|
+
target.watchFiles = source.watchFiles;
|
|
165
|
+
}
|
|
166
|
+
if (source.watchDirs !== void 0) {
|
|
167
|
+
target.watchDirs = source.watchDirs;
|
|
112
168
|
}
|
|
113
|
-
const { path: path2, ...options } = result;
|
|
114
|
-
return { path: path2, options };
|
|
115
169
|
}
|
|
116
170
|
// Annotate the CommonJS export names for ESM import in node:
|
|
117
171
|
0 && (module.exports = {
|
|
@@ -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
|
-
|
|
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 =
|
|
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
|
-
|
|
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 (
|
|
105
|
-
|
|
109
|
+
if (resolvedBabelOptions.sourceMaps) {
|
|
110
|
+
resolvedBabelOptions.sourceFileName = path.basename(args.path);
|
|
106
111
|
}
|
|
107
|
-
const result = await babel.transformAsync(code,
|
|
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
|
-
|
|
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
|
|
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)({
|
|
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(
|
|
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) => {
|
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import type { BuildConfig } from '@granite-js/plugin-core';
|
|
2
2
|
import * as esbuild from 'esbuild';
|
|
3
|
-
export
|
|
3
|
+
export type BuildWithEsbuildResult = esbuild.BuildResult & {
|
|
4
|
+
readonly code: string;
|
|
5
|
+
};
|
|
6
|
+
export declare function buildWithEsbuild(buildConfig: BuildConfig, options?: esbuild.BuildOptions): Promise<BuildWithEsbuildResult>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@granite-js/mpack",
|
|
3
|
-
"version": "1.0.
|
|
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.
|
|
96
|
-
"@granite-js/utils": "1.0.
|
|
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",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const foo: string;
|