@granite-js/mpack 1.0.24 → 1.0.26

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,25 @@
1
1
  # @granite-js/mpack
2
2
 
3
+ ## 1.0.26
4
+
5
+ ### Patch Changes
6
+
7
+ - b50c12f: propagate esbuild resolve result options in alias resolver
8
+ - 4acc9d6: Add INTERNAL\_\_esbuildOptions to allow dynamic configuration of esbuild build options.
9
+ - Updated dependencies [b50c12f]
10
+ - Updated dependencies [4acc9d6]
11
+ - @granite-js/plugin-core@1.0.26
12
+ - @granite-js/utils@1.0.26
13
+
14
+ ## 1.0.25
15
+
16
+ ### Patch Changes
17
+
18
+ - d44c0b0: export withIO API
19
+ - Updated dependencies [d44c0b0]
20
+ - @granite-js/plugin-core@1.0.25
21
+ - @granite-js/utils@1.0.25
22
+
3
23
  ## 1.0.24
4
24
 
5
25
  ### Patch Changes
@@ -66,7 +66,8 @@ class Bundler {
66
66
  async build(options) {
67
67
  const { withDispose = true } = options ?? {};
68
68
  if (this.esbuildContext == null) {
69
- this.esbuildContext = await esbuild.context(this.getBaseBuildOptions());
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
- return {
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 = { ...defaultResolveOptions, ...resolveResult.options ?? {} };
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 = { ...args, path: resolvePath };
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 = (boundArgs, path2, options) => {
90
- const result = resolver({ ...boundArgs, path: path2 }, options);
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), options: void 0 };
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,3 +1,6 @@
1
1
  import type { BuildConfig } from '@granite-js/plugin-core';
2
2
  import * as esbuild from 'esbuild';
3
- export declare function buildWithEsbuild(buildConfig: BuildConfig, options?: esbuild.BuildOptions): Promise<string>;
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.24",
3
+ "version": "1.0.26",
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.24",
96
- "@granite-js/utils": "1.0.24",
95
+ "@granite-js/plugin-core": "1.0.26",
96
+ "@granite-js/utils": "1.0.26",
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",