@atlaspack/core 2.12.1-canary.3463 → 2.12.1-canary.3465

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.
@@ -19,6 +19,7 @@ class MutableAsset {
19
19
  #inner;
20
20
  #ast;
21
21
  #contents;
22
+ #astDirty;
22
23
  get astGenerator() {
23
24
  throw new Error('get MutableAsset.astGenerator');
24
25
  }
@@ -47,6 +48,7 @@ class MutableAsset {
47
48
  this.#contents = Buffer.from(asset.code);
48
49
  this.fs = fs;
49
50
  this.env = env;
51
+ this.#astDirty = false;
50
52
  }
51
53
 
52
54
  // eslint-disable-next-line require-await
@@ -54,10 +56,11 @@ class MutableAsset {
54
56
  return this.#ast;
55
57
  }
56
58
  setAST(ast) {
59
+ this.#astDirty = true;
57
60
  this.#ast = ast;
58
61
  }
59
62
  isASTDirty() {
60
- throw new Error('MutableAsset.isASTDirty()');
63
+ return this.#astDirty;
61
64
  }
62
65
 
63
66
  // eslint-disable-next-line require-await
@@ -91,7 +94,8 @@ class MutableAsset {
91
94
  });
92
95
  }
93
96
  getMap() {
94
- throw new Error('MutableAsset.getMap');
97
+ // TODO: Provide source maps once they exist
98
+ return Promise.resolve(null);
95
99
  }
96
100
 
97
101
  // eslint-disable-next-line no-unused-vars
@@ -122,23 +126,23 @@ class MutableAsset {
122
126
 
123
127
  // eslint-disable-next-line no-unused-vars
124
128
  invalidateOnFileChange() {
125
- throw new Error('MutableAsset.invalidateOnFileChange()');
129
+ // TODO: Forward invalidations to Rust
126
130
  }
127
131
 
128
132
  // eslint-disable-next-line no-unused-vars
129
133
  invalidateOnFileCreate() {
130
- throw new Error('MutableAsset.invalidateOnFileCreate()');
134
+ // TODO: Forward invalidations to Rust
131
135
  }
132
136
 
133
137
  // eslint-disable-next-line no-unused-vars
134
138
  invalidateOnEnvChange() {
135
- throw new Error('MutableAsset.invalidateOnEnvChange()');
139
+ // TODO: Forward invalidations to Rust
136
140
  }
137
141
  invalidateOnStartup() {
138
- throw new Error('MutableAsset.invalidateOnStartup()');
142
+ // TODO: Forward invalidations to Rust
139
143
  }
140
144
  invalidateOnBuild() {
141
- throw new Error('MutableAsset.invalidateOnBuild()');
145
+ // TODO: Forward invalidations to Rust
142
146
  }
143
147
  }
144
148
  exports.MutableAsset = MutableAsset;
@@ -96,7 +96,7 @@ class AtlaspackWorker {
96
96
  dependency: napiDependency,
97
97
  specifier,
98
98
  pipeline,
99
- projectRoot
99
+ options
100
100
  }) => {
101
101
  const state = this.#resolvers.get(key);
102
102
  if (!state) {
@@ -104,7 +104,7 @@ class AtlaspackWorker {
104
104
  }
105
105
  let packageManager = state.packageManager;
106
106
  if (!packageManager) {
107
- packageManager = new (_packageManager().NodePackageManager)(this.#fs, projectRoot);
107
+ packageManager = new (_packageManager().NodePackageManager)(this.#fs, options.projectRoot);
108
108
  state.packageManager = packageManager;
109
109
  }
110
110
  const env = new _compat.Environment(napiDependency.env);
@@ -113,9 +113,9 @@ class AtlaspackWorker {
113
113
  logger: new _compat.PluginLogger(),
114
114
  tracer: new _compat.PluginTracer(),
115
115
  options: new _compat.PluginOptions({
116
+ ...options,
116
117
  packageManager,
117
118
  shouldAutoInstall: false,
118
- projectRoot,
119
119
  inputFS: this.#fs,
120
120
  outputFS: this.#fs
121
121
  })
@@ -164,7 +164,7 @@ class AtlaspackWorker {
164
164
  runTransformerTransform = (0, _jsCallable.jsCallable)(async ({
165
165
  key,
166
166
  env: napiEnv,
167
- projectRoot,
167
+ options,
168
168
  asset: innerAsset
169
169
  }) => {
170
170
  var _transformer$loadConf;
@@ -174,7 +174,7 @@ class AtlaspackWorker {
174
174
  }
175
175
  let packageManager = state.packageManager;
176
176
  if (!packageManager) {
177
- packageManager = new (_packageManager().NodePackageManager)(this.#fs, projectRoot);
177
+ packageManager = new (_packageManager().NodePackageManager)(this.#fs, options.projectRoot);
178
178
  state.packageManager = packageManager;
179
179
  }
180
180
  const transformer = state.transformer;
@@ -184,9 +184,9 @@ class AtlaspackWorker {
184
184
  logger: new _compat.PluginLogger(),
185
185
  tracer: new _compat.PluginTracer(),
186
186
  options: new _compat.PluginOptions({
187
+ ...options,
187
188
  packageManager,
188
189
  shouldAutoInstall: false,
189
- projectRoot,
190
190
  inputFS: this.#fs,
191
191
  outputFS: this.#fs
192
192
  })
@@ -222,21 +222,20 @@ class AtlaspackWorker {
222
222
  });
223
223
  if (transformer.generate) {
224
224
  const ast = await mutableAsset.getAST();
225
- if (!ast) {
226
- throw new Error('Transformer.generate.ast');
227
- }
228
- // $FlowFixMe "Cannot call `transformer.generate` because undefined [1] is not a function." 🤷‍♀️
229
- const output = await transformer.generate({
230
- asset: mutableAsset,
231
- ast,
232
- ...defaultOptions
233
- });
234
- if (typeof output.content === 'string') {
235
- mutableAsset.setCode(output.content);
236
- } else if (output.content instanceof Buffer) {
237
- mutableAsset.setBuffer(output.content);
238
- } else {
239
- mutableAsset.setStream(output.content);
225
+ if (ast) {
226
+ // $FlowFixMe "Cannot call `transformer.generate` because undefined [1] is not a function." 🤷‍♀️
227
+ const output = await transformer.generate({
228
+ asset: mutableAsset,
229
+ ast,
230
+ ...defaultOptions
231
+ });
232
+ if (typeof output.content === 'string') {
233
+ mutableAsset.setCode(output.content);
234
+ } else if (output.content instanceof Buffer) {
235
+ mutableAsset.setBuffer(output.content);
236
+ } else {
237
+ mutableAsset.setStream(output.content);
238
+ }
240
239
  }
241
240
  }
242
241
  (0, _assert().default)(result.length === 1, '[V3] Unimplemented: Multiple asset return from Node transformer');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/core",
3
- "version": "2.12.1-canary.3463+fb58d0760",
3
+ "version": "2.12.1-canary.3465+963983d20",
4
4
  "license": "(MIT OR Apache-2.0)",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -20,20 +20,20 @@
20
20
  "check-ts": "tsc --noEmit index.d.ts"
21
21
  },
22
22
  "dependencies": {
23
- "@atlaspack/cache": "2.12.1-canary.3463+fb58d0760",
24
- "@atlaspack/diagnostic": "2.12.1-canary.3463+fb58d0760",
25
- "@atlaspack/events": "2.12.1-canary.3463+fb58d0760",
26
- "@atlaspack/feature-flags": "2.12.1-canary.3463+fb58d0760",
27
- "@atlaspack/fs": "2.12.1-canary.3463+fb58d0760",
28
- "@atlaspack/graph": "3.2.1-canary.3463+fb58d0760",
29
- "@atlaspack/logger": "2.12.1-canary.3463+fb58d0760",
30
- "@atlaspack/package-manager": "2.12.1-canary.3463+fb58d0760",
31
- "@atlaspack/plugin": "2.12.1-canary.3463+fb58d0760",
32
- "@atlaspack/profiler": "2.12.1-canary.3463+fb58d0760",
33
- "@atlaspack/rust": "2.12.1-canary.3463+fb58d0760",
34
- "@atlaspack/types": "2.12.1-canary.3463+fb58d0760",
35
- "@atlaspack/utils": "2.12.1-canary.3463+fb58d0760",
36
- "@atlaspack/workers": "2.12.1-canary.3463+fb58d0760",
23
+ "@atlaspack/cache": "2.12.1-canary.3465+963983d20",
24
+ "@atlaspack/diagnostic": "2.12.1-canary.3465+963983d20",
25
+ "@atlaspack/events": "2.12.1-canary.3465+963983d20",
26
+ "@atlaspack/feature-flags": "2.12.1-canary.3465+963983d20",
27
+ "@atlaspack/fs": "2.12.1-canary.3465+963983d20",
28
+ "@atlaspack/graph": "3.2.1-canary.3465+963983d20",
29
+ "@atlaspack/logger": "2.12.1-canary.3465+963983d20",
30
+ "@atlaspack/package-manager": "2.12.1-canary.3465+963983d20",
31
+ "@atlaspack/plugin": "2.12.1-canary.3465+963983d20",
32
+ "@atlaspack/profiler": "2.12.1-canary.3465+963983d20",
33
+ "@atlaspack/rust": "2.12.1-canary.3465+963983d20",
34
+ "@atlaspack/types": "2.12.1-canary.3465+963983d20",
35
+ "@atlaspack/utils": "2.12.1-canary.3465+963983d20",
36
+ "@atlaspack/workers": "2.12.1-canary.3465+963983d20",
37
37
  "@mischnic/json-sourcemap": "^0.1.0",
38
38
  "@parcel/source-map": "^2.1.1",
39
39
  "base-x": "^3.0.8",
@@ -64,5 +64,5 @@
64
64
  "browser": {
65
65
  "./src/serializerCore.js": "./src/serializerCore.browser.js"
66
66
  },
67
- "gitHead": "fb58d07602ff89f132a7c5c985fce2a47e3ebe84"
67
+ "gitHead": "963983d206eac681e7a2bc8cd08043e42d0440a8"
68
68
  }
@@ -43,6 +43,7 @@ export class MutableAsset implements IMutableAsset {
43
43
  #inner: InnerAsset;
44
44
  #ast: ?AST;
45
45
  #contents: Buffer;
46
+ #astDirty: boolean;
46
47
 
47
48
  get astGenerator(): ?ASTGenerator {
48
49
  throw new Error('get MutableAsset.astGenerator');
@@ -74,6 +75,7 @@ export class MutableAsset implements IMutableAsset {
74
75
  this.#contents = Buffer.from(asset.code);
75
76
  this.fs = fs;
76
77
  this.env = env;
78
+ this.#astDirty = false;
77
79
  }
78
80
 
79
81
  // eslint-disable-next-line require-await
@@ -82,11 +84,12 @@ export class MutableAsset implements IMutableAsset {
82
84
  }
83
85
 
84
86
  setAST(ast: AST): void {
87
+ this.#astDirty = true;
85
88
  this.#ast = ast;
86
89
  }
87
90
 
88
91
  isASTDirty(): boolean {
89
- throw new Error('MutableAsset.isASTDirty()');
92
+ return this.#astDirty;
90
93
  }
91
94
 
92
95
  // eslint-disable-next-line require-await
@@ -128,7 +131,8 @@ export class MutableAsset implements IMutableAsset {
128
131
  }
129
132
 
130
133
  getMap(): Promise<?SourceMap> {
131
- throw new Error('MutableAsset.getMap');
134
+ // TODO: Provide source maps once they exist
135
+ return Promise.resolve(null);
132
136
  }
133
137
 
134
138
  // eslint-disable-next-line no-unused-vars
@@ -161,24 +165,24 @@ export class MutableAsset implements IMutableAsset {
161
165
 
162
166
  // eslint-disable-next-line no-unused-vars
163
167
  invalidateOnFileChange(invalidation: FilePath): void {
164
- throw new Error('MutableAsset.invalidateOnFileChange()');
168
+ // TODO: Forward invalidations to Rust
165
169
  }
166
170
 
167
171
  // eslint-disable-next-line no-unused-vars
168
172
  invalidateOnFileCreate(invalidation: FileCreateInvalidation): void {
169
- throw new Error('MutableAsset.invalidateOnFileCreate()');
173
+ // TODO: Forward invalidations to Rust
170
174
  }
171
175
 
172
176
  // eslint-disable-next-line no-unused-vars
173
177
  invalidateOnEnvChange(invalidation: string): void {
174
- throw new Error('MutableAsset.invalidateOnEnvChange()');
178
+ // TODO: Forward invalidations to Rust
175
179
  }
176
180
 
177
181
  invalidateOnStartup(): void {
178
- throw new Error('MutableAsset.invalidateOnStartup()');
182
+ // TODO: Forward invalidations to Rust
179
183
  }
180
184
 
181
185
  invalidateOnBuild(): void {
182
- throw new Error('MutableAsset.invalidateOnBuild()');
186
+ // TODO: Forward invalidations to Rust
183
187
  }
184
188
  }
@@ -76,13 +76,7 @@ export class AtlaspackWorker {
76
76
  [RunResolverResolveOptions],
77
77
  Promise<RunResolverResolveResult>,
78
78
  > = jsCallable(
79
- async ({
80
- key,
81
- dependency: napiDependency,
82
- specifier,
83
- pipeline,
84
- projectRoot,
85
- }) => {
79
+ async ({key, dependency: napiDependency, specifier, pipeline, options}) => {
86
80
  const state = this.#resolvers.get(key);
87
81
  if (!state) {
88
82
  throw new Error(`Resolver not found: ${key}`);
@@ -90,7 +84,7 @@ export class AtlaspackWorker {
90
84
 
91
85
  let packageManager = state.packageManager;
92
86
  if (!packageManager) {
93
- packageManager = new NodePackageManager(this.#fs, projectRoot);
87
+ packageManager = new NodePackageManager(this.#fs, options.projectRoot);
94
88
  state.packageManager = packageManager;
95
89
  }
96
90
 
@@ -101,9 +95,9 @@ export class AtlaspackWorker {
101
95
  logger: new PluginLogger(),
102
96
  tracer: new PluginTracer(),
103
97
  options: new PluginOptions({
98
+ ...options,
104
99
  packageManager,
105
100
  shouldAutoInstall: false,
106
- projectRoot,
107
101
  inputFS: this.#fs,
108
102
  outputFS: this.#fs,
109
103
  }),
@@ -155,71 +149,68 @@ export class AtlaspackWorker {
155
149
  runTransformerTransform: JsCallable<
156
150
  [RunTransformerTransformOptions],
157
151
  Promise<RunTransformerTransformResult>,
158
- > = jsCallable(
159
- async ({key, env: napiEnv, projectRoot, asset: innerAsset}) => {
160
- const state = this.#transformers.get(key);
161
- if (!state) {
162
- throw new Error(`Transformer not found: ${key}`);
163
- }
164
-
165
- let packageManager = state.packageManager;
166
- if (!packageManager) {
167
- packageManager = new NodePackageManager(this.#fs, projectRoot);
168
- state.packageManager = packageManager;
169
- }
170
-
171
- const transformer: Transformer<any> = state.transformer;
172
- const env = new Environment(napiEnv);
173
- const mutableAsset = new MutableAsset(innerAsset, this.#fs, env);
174
- const defaultOptions = {
175
- logger: new PluginLogger(),
176
- tracer: new PluginTracer(),
177
- options: new PluginOptions({
178
- packageManager,
179
- shouldAutoInstall: false,
180
- projectRoot,
181
- inputFS: this.#fs,
182
- outputFS: this.#fs,
183
- }),
184
- };
185
-
186
- const config = await transformer.loadConfig?.({
187
- config: new PluginConfig({
188
- env,
189
- isSource: true,
190
- searchPath: '',
191
- }),
192
- ...defaultOptions,
193
- });
194
-
195
- if (transformer.parse) {
196
- const ast = await transformer.parse({
197
- asset: mutableAsset,
198
- config,
199
- get resolve() {
200
- throw new Error('Transformer.parse.resolve()');
201
- },
202
- ...defaultOptions,
203
- });
204
- if (ast) {
205
- mutableAsset.setAST(ast);
206
- }
207
- }
208
-
209
- const result = await state.transformer.transform({
152
+ > = jsCallable(async ({key, env: napiEnv, options, asset: innerAsset}) => {
153
+ const state = this.#transformers.get(key);
154
+ if (!state) {
155
+ throw new Error(`Transformer not found: ${key}`);
156
+ }
157
+
158
+ let packageManager = state.packageManager;
159
+ if (!packageManager) {
160
+ packageManager = new NodePackageManager(this.#fs, options.projectRoot);
161
+ state.packageManager = packageManager;
162
+ }
163
+
164
+ const transformer: Transformer<any> = state.transformer;
165
+ const env = new Environment(napiEnv);
166
+ const mutableAsset = new MutableAsset(innerAsset, this.#fs, env);
167
+ const defaultOptions = {
168
+ logger: new PluginLogger(),
169
+ tracer: new PluginTracer(),
170
+ options: new PluginOptions({
171
+ ...options,
172
+ packageManager,
173
+ shouldAutoInstall: false,
174
+ inputFS: this.#fs,
175
+ outputFS: this.#fs,
176
+ }),
177
+ };
178
+
179
+ const config = await transformer.loadConfig?.({
180
+ config: new PluginConfig({
181
+ env,
182
+ isSource: true,
183
+ searchPath: '',
184
+ }),
185
+ ...defaultOptions,
186
+ });
187
+
188
+ if (transformer.parse) {
189
+ const ast = await transformer.parse({
210
190
  asset: mutableAsset,
211
191
  config,
212
192
  get resolve() {
213
- throw new Error('Transformer.transform.resolve()');
193
+ throw new Error('Transformer.parse.resolve()');
214
194
  },
215
195
  ...defaultOptions,
216
196
  });
217
-
218
- if (transformer.generate) {
219
- const ast = await mutableAsset.getAST();
220
- if (!ast) {
221
- throw new Error('Transformer.generate.ast');
222
- }
197
+ if (ast) {
198
+ mutableAsset.setAST(ast);
199
+ }
200
+ }
201
+
202
+ const result = await state.transformer.transform({
203
+ asset: mutableAsset,
204
+ config,
205
+ get resolve() {
206
+ throw new Error('Transformer.transform.resolve()');
207
+ },
208
+ ...defaultOptions,
209
+ });
210
+
211
+ if (transformer.generate) {
212
+ const ast = await mutableAsset.getAST();
213
+ if (ast) {
223
214
  // $FlowFixMe "Cannot call `transformer.generate` because undefined [1] is not a function." 🤷‍♀️
224
215
  const output = await transformer.generate({
225
216
  asset: mutableAsset,
@@ -235,38 +226,38 @@ export class AtlaspackWorker {
235
226
  mutableAsset.setStream(output.content);
236
227
  }
237
228
  }
238
-
239
- assert(
240
- result.length === 1,
241
- '[V3] Unimplemented: Multiple asset return from Node transformer',
242
- );
243
-
244
- assert(
245
- result[0] === mutableAsset,
246
- '[V3] Unimplemented: New asset returned from Node transformer',
247
- );
248
-
249
- return {
250
- asset: {
251
- id: mutableAsset.id,
252
- bundleBehavior: bundleBehaviorMap.intoNullable(
253
- mutableAsset.bundleBehavior,
254
- ),
255
- filePath: mutableAsset.filePath,
256
- type: mutableAsset.type,
257
- code: Array.from(await mutableAsset.getBuffer()),
258
- meta: mutableAsset.meta,
259
- pipeline: mutableAsset.pipeline,
260
- query: mutableAsset.query.toString(),
261
- symbols: mutableAsset.symbols.intoNapi(),
262
- uniqueKey: mutableAsset.uniqueKey,
263
- sideEffects: mutableAsset.sideEffects,
264
- isBundleSplittable: mutableAsset.isBundleSplittable,
265
- isSource: mutableAsset.isSource,
266
- },
267
- };
268
- },
269
- );
229
+ }
230
+
231
+ assert(
232
+ result.length === 1,
233
+ '[V3] Unimplemented: Multiple asset return from Node transformer',
234
+ );
235
+
236
+ assert(
237
+ result[0] === mutableAsset,
238
+ '[V3] Unimplemented: New asset returned from Node transformer',
239
+ );
240
+
241
+ return {
242
+ asset: {
243
+ id: mutableAsset.id,
244
+ bundleBehavior: bundleBehaviorMap.intoNullable(
245
+ mutableAsset.bundleBehavior,
246
+ ),
247
+ filePath: mutableAsset.filePath,
248
+ type: mutableAsset.type,
249
+ code: Array.from(await mutableAsset.getBuffer()),
250
+ meta: mutableAsset.meta,
251
+ pipeline: mutableAsset.pipeline,
252
+ query: mutableAsset.query.toString(),
253
+ symbols: mutableAsset.symbols.intoNapi(),
254
+ uniqueKey: mutableAsset.uniqueKey,
255
+ sideEffects: mutableAsset.sideEffects,
256
+ isBundleSplittable: mutableAsset.isBundleSplittable,
257
+ isSource: mutableAsset.isSource,
258
+ },
259
+ };
260
+ });
270
261
  }
271
262
 
272
263
  napi.registerWorker(workerData.tx_worker, new AtlaspackWorker());
@@ -288,12 +279,17 @@ type LoadPluginOptions = {|
288
279
  resolveFrom: string,
289
280
  |};
290
281
 
282
+ type RpcPluginOptions = {|
283
+ projectRoot: string,
284
+ mode: string,
285
+ |};
286
+
291
287
  type RunResolverResolveOptions = {|
292
288
  key: string,
293
289
  dependency: napi.Dependency,
294
290
  specifier: FilePath,
295
291
  pipeline: ?string,
296
- projectRoot: string,
292
+ options: RpcPluginOptions,
297
293
  |};
298
294
 
299
295
  type RunResolverResolveResult = {|
@@ -317,7 +313,7 @@ type RunResolverResolveResult = {|
317
313
  type RunTransformerTransformOptions = {|
318
314
  key: string,
319
315
  env: napi.Environment,
320
- projectRoot: string,
316
+ options: RpcPluginOptions,
321
317
  asset: napi.Asset,
322
318
  |};
323
319