@atlaspack/core 2.12.1-canary.3427 → 2.12.1-canary.3429

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.
@@ -33,11 +33,82 @@ function _module() {
33
33
  return data;
34
34
  }
35
35
  var _compat = require("./compat");
36
+ var _jsCallable = require("../jsCallable");
36
37
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
37
38
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
38
39
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
39
40
  const CONFIG = Symbol.for('parcel-plugin-config');
40
41
  class AtlaspackWorker {
42
+ #resolvers;
43
+ constructor() {
44
+ this.#resolvers = new Map();
45
+ }
46
+ loadPlugin = (0, _jsCallable.jsCallable)(async ({
47
+ kind,
48
+ specifier,
49
+ resolveFrom
50
+ }) => {
51
+ let customRequire = _module().createRequire(resolveFrom);
52
+ let resolvedPath = customRequire.resolve(specifier);
53
+ // $FlowFixMe
54
+ let resolvedModule = await import(resolvedPath);
55
+ switch (kind) {
56
+ case 'resolver':
57
+ this.#resolvers.set(specifier, resolvedModule.default[CONFIG]);
58
+ break;
59
+ }
60
+ });
61
+ runResolverResolve = (0, _jsCallable.jsCallable)(async ({
62
+ key,
63
+ dependency,
64
+ specifier
65
+ }) => {
66
+ const resolver = this.#resolvers.get(key);
67
+ if (!resolver) {
68
+ throw new Error('Resolver not found');
69
+ }
70
+ const result = await resolver.resolve({
71
+ specifier,
72
+ dependency,
73
+ get options() {
74
+ throw new Error('TODO: Resolver.resolve.options');
75
+ },
76
+ get logger() {
77
+ throw new Error('TODO: Resolver.resolve.logger');
78
+ },
79
+ get tracer() {
80
+ throw new Error('TODO: Resolver.resolve.tracer');
81
+ },
82
+ get pipeline() {
83
+ throw new Error('TODO: Resolver.resolve.pipeline');
84
+ },
85
+ get config() {
86
+ throw new Error('TODO: Resolver.resolve.config');
87
+ }
88
+ });
89
+ if (!result) {
90
+ return {
91
+ invalidations: [],
92
+ resolution: {
93
+ type: 'unresolved'
94
+ }
95
+ };
96
+ }
97
+ return {
98
+ invalidations: [],
99
+ resolution: {
100
+ type: 'resolved',
101
+ filePath: result.filePath || '',
102
+ canDefer: result.canDefer || false,
103
+ sideEffects: result.sideEffects || false,
104
+ code: result.code || undefined,
105
+ meta: result.meta || undefined,
106
+ pipeline: result.pipeline || undefined,
107
+ priority: result.priority && PriorityMap[result.priority],
108
+ query: result.query && result.query.toString()
109
+ }
110
+ };
111
+ });
41
112
  ping() {
42
113
  // console.log('Hi');
43
114
  }
@@ -97,4 +168,9 @@ class AtlaspackWorker {
97
168
  }
98
169
  }
99
170
  exports.AtlaspackWorker = AtlaspackWorker;
100
- napi().registerWorker(_worker_threads().workerData.tx_worker, new AtlaspackWorker());
171
+ napi().registerWorker(_worker_threads().workerData.tx_worker, new AtlaspackWorker());
172
+ const PriorityMap = {
173
+ sync: 0,
174
+ parallel: 1,
175
+ lazy: 2
176
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/core",
3
- "version": "2.12.1-canary.3427+a86b8559a",
3
+ "version": "2.12.1-canary.3429+8cd6d09ce",
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.3427+a86b8559a",
24
- "@atlaspack/diagnostic": "2.12.1-canary.3427+a86b8559a",
25
- "@atlaspack/events": "2.12.1-canary.3427+a86b8559a",
26
- "@atlaspack/feature-flags": "2.12.1-canary.3427+a86b8559a",
27
- "@atlaspack/fs": "2.12.1-canary.3427+a86b8559a",
28
- "@atlaspack/graph": "3.2.1-canary.3427+a86b8559a",
29
- "@atlaspack/logger": "2.12.1-canary.3427+a86b8559a",
30
- "@atlaspack/package-manager": "2.12.1-canary.3427+a86b8559a",
31
- "@atlaspack/plugin": "2.12.1-canary.3427+a86b8559a",
32
- "@atlaspack/profiler": "2.12.1-canary.3427+a86b8559a",
33
- "@atlaspack/rust": "2.12.1-canary.3427+a86b8559a",
34
- "@atlaspack/types": "2.12.1-canary.3427+a86b8559a",
35
- "@atlaspack/utils": "2.12.1-canary.3427+a86b8559a",
36
- "@atlaspack/workers": "2.12.1-canary.3427+a86b8559a",
23
+ "@atlaspack/cache": "2.12.1-canary.3429+8cd6d09ce",
24
+ "@atlaspack/diagnostic": "2.12.1-canary.3429+8cd6d09ce",
25
+ "@atlaspack/events": "2.12.1-canary.3429+8cd6d09ce",
26
+ "@atlaspack/feature-flags": "2.12.1-canary.3429+8cd6d09ce",
27
+ "@atlaspack/fs": "2.12.1-canary.3429+8cd6d09ce",
28
+ "@atlaspack/graph": "3.2.1-canary.3429+8cd6d09ce",
29
+ "@atlaspack/logger": "2.12.1-canary.3429+8cd6d09ce",
30
+ "@atlaspack/package-manager": "2.12.1-canary.3429+8cd6d09ce",
31
+ "@atlaspack/plugin": "2.12.1-canary.3429+8cd6d09ce",
32
+ "@atlaspack/profiler": "2.12.1-canary.3429+8cd6d09ce",
33
+ "@atlaspack/rust": "2.12.1-canary.3429+8cd6d09ce",
34
+ "@atlaspack/types": "2.12.1-canary.3429+8cd6d09ce",
35
+ "@atlaspack/utils": "2.12.1-canary.3429+8cd6d09ce",
36
+ "@atlaspack/workers": "2.12.1-canary.3429+8cd6d09ce",
37
37
  "@mischnic/json-sourcemap": "^0.1.0",
38
38
  "@parcel/source-map": "^2.1.1",
39
39
  "base-x": "^3.0.8",
@@ -57,5 +57,5 @@
57
57
  "browser": {
58
58
  "./src/serializerCore.js": "./src/serializerCore.browser.js"
59
59
  },
60
- "gitHead": "a86b8559a2aefd7033eb14e71320308f7ece0122"
60
+ "gitHead": "8cd6d09ce1b68f1848c298ea900334b8d47c9fd9"
61
61
  }
@@ -1,5 +1,9 @@
1
1
  // @flow strict-local
2
2
 
3
+ export type JsCallable<Args: $ReadOnlyArray<mixed>, Return> = (
4
+ ...Args
5
+ ) => Return;
6
+
3
7
  export function jsCallable<Args: $ReadOnlyArray<mixed>, Return>(
4
8
  fn: (...Args) => Return,
5
9
  ): (...Args) => Return {
@@ -1,16 +1,97 @@
1
1
  // @flow
2
2
  import assert from 'assert';
3
3
  import * as napi from '@atlaspack/rust';
4
- import type {Transformer, PluginOptions} from '@atlaspack/types';
4
+ import type {
5
+ Resolver,
6
+ Transformer,
7
+ PluginOptions,
8
+ Dependency,
9
+ FilePath,
10
+ } from '@atlaspack/types';
5
11
  import {workerData} from 'worker_threads';
6
12
  import * as module from 'module';
7
13
 
8
14
  import {AssetCompat} from './compat';
9
15
  import type {InnerAsset} from './compat';
16
+ import {jsCallable} from '../jsCallable';
17
+ import type {JsCallable} from '../jsCallable';
10
18
 
11
19
  const CONFIG = Symbol.for('parcel-plugin-config');
12
20
 
13
21
  export class AtlaspackWorker {
22
+ #resolvers: Map<string, Resolver<*>>;
23
+
24
+ constructor() {
25
+ this.#resolvers = new Map();
26
+ }
27
+
28
+ loadPlugin: JsCallable<[LoadPluginOptions], Promise<void>> = jsCallable(
29
+ async ({kind, specifier, resolveFrom}) => {
30
+ let customRequire = module.createRequire(resolveFrom);
31
+ let resolvedPath = customRequire.resolve(specifier);
32
+ // $FlowFixMe
33
+ let resolvedModule = await import(resolvedPath);
34
+
35
+ switch (kind) {
36
+ case 'resolver':
37
+ this.#resolvers.set(specifier, resolvedModule.default[CONFIG]);
38
+ break;
39
+ }
40
+ },
41
+ );
42
+
43
+ runResolverResolve: JsCallable<
44
+ [RunResolverResolveOptions],
45
+ Promise<RunResolverResolveResult>,
46
+ > = jsCallable(async ({key, dependency, specifier}) => {
47
+ const resolver = this.#resolvers.get(key);
48
+ if (!resolver) {
49
+ throw new Error('Resolver not found');
50
+ }
51
+
52
+ const result = await resolver.resolve({
53
+ specifier,
54
+ dependency,
55
+ get options() {
56
+ throw new Error('TODO: Resolver.resolve.options');
57
+ },
58
+ get logger() {
59
+ throw new Error('TODO: Resolver.resolve.logger');
60
+ },
61
+ get tracer() {
62
+ throw new Error('TODO: Resolver.resolve.tracer');
63
+ },
64
+ get pipeline() {
65
+ throw new Error('TODO: Resolver.resolve.pipeline');
66
+ },
67
+ get config() {
68
+ throw new Error('TODO: Resolver.resolve.config');
69
+ },
70
+ });
71
+
72
+ if (!result) {
73
+ return {
74
+ invalidations: [],
75
+ resolution: {type: 'unresolved'},
76
+ };
77
+ }
78
+
79
+ return {
80
+ invalidations: [],
81
+ resolution: {
82
+ type: 'resolved',
83
+ filePath: result.filePath || '',
84
+ canDefer: result.canDefer || false,
85
+ sideEffects: result.sideEffects || false,
86
+ code: result.code || undefined,
87
+ meta: result.meta || undefined,
88
+ pipeline: result.pipeline || undefined,
89
+ priority: result.priority && PriorityMap[result.priority],
90
+ query: result.query && result.query.toString(),
91
+ },
92
+ };
93
+ });
94
+
14
95
  ping() {
15
96
  // console.log('Hi');
16
97
  }
@@ -87,3 +168,39 @@ export class AtlaspackWorker {
87
168
  }
88
169
 
89
170
  napi.registerWorker(workerData.tx_worker, new AtlaspackWorker());
171
+
172
+ type LoadPluginOptions = {|
173
+ kind: 'resolver',
174
+ specifier: string,
175
+ resolveFrom: string,
176
+ |};
177
+
178
+ type RunResolverResolveOptions = {|
179
+ key: string,
180
+ dependency: Dependency,
181
+ specifier: FilePath,
182
+ |};
183
+
184
+ type RunResolverResolveResult = {|
185
+ invalidations: Array<*>,
186
+ resolution:
187
+ | {|type: 'unresolved'|}
188
+ | {|type: 'excluded'|}
189
+ | {|
190
+ type: 'resolved',
191
+ canDefer: boolean,
192
+ filePath: string,
193
+ sideEffects: boolean,
194
+ code?: string,
195
+ meta?: mixed,
196
+ pipeline?: string,
197
+ priority?: number,
198
+ query?: string,
199
+ |},
200
+ |};
201
+
202
+ const PriorityMap = {
203
+ sync: 0,
204
+ parallel: 1,
205
+ lazy: 2,
206
+ };