@atlaspack/core 2.12.1-canary.3354

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.
Files changed (215) hide show
  1. package/LICENSE +201 -0
  2. package/index.d.ts +22 -0
  3. package/lib/AssetGraph.js +518 -0
  4. package/lib/Atlaspack.js +587 -0
  5. package/lib/AtlaspackConfig.js +298 -0
  6. package/lib/AtlaspackConfig.schema.js +125 -0
  7. package/lib/BundleGraph.js +1445 -0
  8. package/lib/CommittedAsset.js +133 -0
  9. package/lib/Dependency.js +88 -0
  10. package/lib/Environment.js +128 -0
  11. package/lib/InternalConfig.js +48 -0
  12. package/lib/PackagerRunner.js +519 -0
  13. package/lib/ReporterRunner.js +151 -0
  14. package/lib/RequestTracker.js +1089 -0
  15. package/lib/SymbolPropagation.js +625 -0
  16. package/lib/TargetDescriptor.schema.js +115 -0
  17. package/lib/Transformation.js +536 -0
  18. package/lib/UncommittedAsset.js +342 -0
  19. package/lib/Validation.js +215 -0
  20. package/lib/applyRuntimes.js +279 -0
  21. package/lib/assetUtils.js +189 -0
  22. package/lib/atlaspack-v3/AtlaspackV3.js +74 -0
  23. package/lib/atlaspack-v3/fs.js +30 -0
  24. package/lib/atlaspack-v3/index.js +19 -0
  25. package/lib/atlaspack-v3/jsCallable.js +15 -0
  26. package/lib/atlaspack-v3/plugins/Resolver.js +12 -0
  27. package/lib/atlaspack-v3/plugins/index.js +16 -0
  28. package/lib/atlaspack-v3/worker/index.js +3 -0
  29. package/lib/atlaspack-v3/worker/worker.js +30 -0
  30. package/lib/buildCache.js +18 -0
  31. package/lib/constants.js +21 -0
  32. package/lib/dumpGraphToGraphViz.js +206 -0
  33. package/lib/index.js +106 -0
  34. package/lib/loadAtlaspackPlugin.js +148 -0
  35. package/lib/loadDotEnv.js +54 -0
  36. package/lib/projectPath.js +86 -0
  37. package/lib/public/Asset.js +259 -0
  38. package/lib/public/Bundle.js +231 -0
  39. package/lib/public/BundleGraph.js +193 -0
  40. package/lib/public/BundleGroup.js +44 -0
  41. package/lib/public/Config.js +202 -0
  42. package/lib/public/Dependency.js +131 -0
  43. package/lib/public/Environment.js +244 -0
  44. package/lib/public/MutableBundleGraph.js +184 -0
  45. package/lib/public/PluginOptions.js +71 -0
  46. package/lib/public/Symbols.js +247 -0
  47. package/lib/public/Target.js +64 -0
  48. package/lib/registerCoreWithSerializer.js +45 -0
  49. package/lib/requests/AssetGraphRequest.js +427 -0
  50. package/lib/requests/AssetGraphRequestRust.js +187 -0
  51. package/lib/requests/AssetRequest.js +137 -0
  52. package/lib/requests/AtlaspackBuildRequest.js +78 -0
  53. package/lib/requests/AtlaspackConfigRequest.js +473 -0
  54. package/lib/requests/BundleGraphRequest.js +419 -0
  55. package/lib/requests/ConfigRequest.js +198 -0
  56. package/lib/requests/DevDepRequest.js +166 -0
  57. package/lib/requests/EntryRequest.js +295 -0
  58. package/lib/requests/PackageRequest.js +88 -0
  59. package/lib/requests/PathRequest.js +349 -0
  60. package/lib/requests/TargetRequest.js +1177 -0
  61. package/lib/requests/ValidationRequest.js +66 -0
  62. package/lib/requests/WriteBundleRequest.js +252 -0
  63. package/lib/requests/WriteBundlesRequest.js +153 -0
  64. package/lib/resolveOptions.js +234 -0
  65. package/lib/serializer.js +216 -0
  66. package/lib/serializerCore.browser.js +29 -0
  67. package/lib/serializerCore.js +16 -0
  68. package/lib/summarizeRequest.js +55 -0
  69. package/lib/types.js +35 -0
  70. package/lib/utils.js +160 -0
  71. package/lib/worker.js +170 -0
  72. package/package.json +59 -0
  73. package/src/AssetGraph.js +646 -0
  74. package/src/Atlaspack.js +632 -0
  75. package/src/AtlaspackConfig.js +490 -0
  76. package/src/AtlaspackConfig.schema.js +141 -0
  77. package/src/BundleGraph.js +2193 -0
  78. package/src/CommittedAsset.js +143 -0
  79. package/src/Dependency.js +142 -0
  80. package/src/Environment.js +151 -0
  81. package/src/InternalConfig.js +72 -0
  82. package/src/PackagerRunner.js +790 -0
  83. package/src/ReporterRunner.js +158 -0
  84. package/src/RequestTracker.js +1697 -0
  85. package/src/SymbolPropagation.js +794 -0
  86. package/src/TargetDescriptor.schema.js +136 -0
  87. package/src/Transformation.js +752 -0
  88. package/src/UncommittedAsset.js +426 -0
  89. package/src/Validation.js +223 -0
  90. package/src/applyRuntimes.js +341 -0
  91. package/src/assetUtils.js +254 -0
  92. package/src/atlaspack-v3/AtlaspackV3.js +73 -0
  93. package/src/atlaspack-v3/fs.js +36 -0
  94. package/src/atlaspack-v3/index.js +5 -0
  95. package/src/atlaspack-v3/jsCallable.js +13 -0
  96. package/src/atlaspack-v3/plugins/Resolver.js +9 -0
  97. package/src/atlaspack-v3/plugins/index.js +3 -0
  98. package/src/atlaspack-v3/worker/index.js +8 -0
  99. package/src/atlaspack-v3/worker/worker.js +14 -0
  100. package/src/buildCache.js +15 -0
  101. package/src/constants.js +22 -0
  102. package/src/dumpGraphToGraphViz.js +244 -0
  103. package/src/index.js +22 -0
  104. package/src/loadAtlaspackPlugin.js +239 -0
  105. package/src/loadDotEnv.js +56 -0
  106. package/src/projectPath.js +87 -0
  107. package/src/public/Asset.js +359 -0
  108. package/src/public/Bundle.js +337 -0
  109. package/src/public/BundleGraph.js +335 -0
  110. package/src/public/BundleGroup.js +55 -0
  111. package/src/public/Config.js +261 -0
  112. package/src/public/Dependency.js +176 -0
  113. package/src/public/Environment.js +316 -0
  114. package/src/public/MutableBundleGraph.js +320 -0
  115. package/src/public/PluginOptions.js +99 -0
  116. package/src/public/Symbols.js +315 -0
  117. package/src/public/Target.js +71 -0
  118. package/src/registerCoreWithSerializer.js +34 -0
  119. package/src/requests/AssetGraphRequest.js +577 -0
  120. package/src/requests/AssetGraphRequestRust.js +222 -0
  121. package/src/requests/AssetRequest.js +179 -0
  122. package/src/requests/AtlaspackBuildRequest.js +109 -0
  123. package/src/requests/AtlaspackConfigRequest.js +709 -0
  124. package/src/requests/BundleGraphRequest.js +547 -0
  125. package/src/requests/ConfigRequest.js +287 -0
  126. package/src/requests/DevDepRequest.js +246 -0
  127. package/src/requests/EntryRequest.js +385 -0
  128. package/src/requests/PackageRequest.js +105 -0
  129. package/src/requests/PathRequest.js +454 -0
  130. package/src/requests/TargetRequest.js +1632 -0
  131. package/src/requests/ValidationRequest.js +79 -0
  132. package/src/requests/WriteBundleRequest.js +362 -0
  133. package/src/requests/WriteBundlesRequest.js +209 -0
  134. package/src/resolveOptions.js +278 -0
  135. package/src/serializer.js +255 -0
  136. package/src/serializerCore.browser.js +8 -0
  137. package/src/serializerCore.js +5 -0
  138. package/src/summarizeRequest.js +47 -0
  139. package/src/types.js +581 -0
  140. package/src/utils.js +211 -0
  141. package/src/worker.js +189 -0
  142. package/test/AssetGraph.test.js +679 -0
  143. package/test/Atlaspack.test.js +142 -0
  144. package/test/AtlaspackConfig.test.js +405 -0
  145. package/test/AtlaspackConfigRequest.test.js +993 -0
  146. package/test/BundleGraph.test.js +121 -0
  147. package/test/EntryRequest.test.js +215 -0
  148. package/test/Environment.test.js +99 -0
  149. package/test/InternalAsset.test.js +76 -0
  150. package/test/PackagerRunner.test.js +27 -0
  151. package/test/PublicAsset.test.js +40 -0
  152. package/test/PublicBundle.test.js +68 -0
  153. package/test/PublicDependency.test.js +22 -0
  154. package/test/PublicEnvironment.test.js +27 -0
  155. package/test/PublicMutableBundleGraph.test.js +192 -0
  156. package/test/RequestTracker.test.js +448 -0
  157. package/test/SymbolPropagation.test.js +716 -0
  158. package/test/TargetRequest.test.js +1715 -0
  159. package/test/fixtures/application-targets/package.json +3 -0
  160. package/test/fixtures/atlaspack/index.js +1 -0
  161. package/test/fixtures/atlaspack/other.js +3 -0
  162. package/test/fixtures/atlaspack/package.json +1 -0
  163. package/test/fixtures/atlaspack/yarn.lock +0 -0
  164. package/test/fixtures/bundle.js +10 -0
  165. package/test/fixtures/common-targets/package.json +24 -0
  166. package/test/fixtures/common-targets-ignore/package.json +13 -0
  167. package/test/fixtures/config/.atlaspackrc +6 -0
  168. package/test/fixtures/config/subfolder/.atlaspackrc +6 -0
  169. package/test/fixtures/config-extends-not-found/.atlaspackrc +3 -0
  170. package/test/fixtures/config-extends-not-found/.atlaspackrc-json5 +3 -0
  171. package/test/fixtures/config-extends-not-found/.atlaspackrc-multiple +3 -0
  172. package/test/fixtures/config-extends-not-found/.atlaspackrc-node-modules +3 -0
  173. package/test/fixtures/config-malformed/.atlaspackrc +3 -0
  174. package/test/fixtures/config-node-pipeline/.atlaspackrc +6 -0
  175. package/test/fixtures/config-plugin-not-found/.atlaspackrc +6 -0
  176. package/test/fixtures/context/package.json +8 -0
  177. package/test/fixtures/custom-format-infer-ext/package.json +6 -0
  178. package/test/fixtures/custom-format-infer-type/package.json +7 -0
  179. package/test/fixtures/custom-format-mismatch/package.json +8 -0
  180. package/test/fixtures/custom-targets/package.json +20 -0
  181. package/test/fixtures/custom-targets-distdir/package.json +11 -0
  182. package/test/fixtures/duplicate-targets/package.json +4 -0
  183. package/test/fixtures/glob-like/[entry].js +0 -0
  184. package/test/fixtures/invalid-distpath/package.json +11 -0
  185. package/test/fixtures/invalid-engines/package.json +12 -0
  186. package/test/fixtures/invalid-source-missing/package.json +5 -0
  187. package/test/fixtures/invalid-source-not-file/package.json +5 -0
  188. package/test/fixtures/invalid-source-not-file/src/index.js +1 -0
  189. package/test/fixtures/invalid-target-source-missing/package.json +9 -0
  190. package/test/fixtures/invalid-target-source-not-file/package.json +9 -0
  191. package/test/fixtures/invalid-target-source-not-file/src/index.js +1 -0
  192. package/test/fixtures/invalid-targets/package.json +19 -0
  193. package/test/fixtures/library-custom-scopehoist/package.json +9 -0
  194. package/test/fixtures/library-scopehoist/package.json +8 -0
  195. package/test/fixtures/local-plugin-config-pkg/.atlaspackrc +3 -0
  196. package/test/fixtures/local-plugin-config-pkg/node_modules/atlaspack-config-local/index.json +8 -0
  197. package/test/fixtures/local-plugin-config-pkg/node_modules/atlaspack-config-local/local-plugin.js +7 -0
  198. package/test/fixtures/local-plugin-config-pkg/node_modules/atlaspack-config-local/package.json +7 -0
  199. package/test/fixtures/main-format-mismatch/package.json +8 -0
  200. package/test/fixtures/main-global/package.json +8 -0
  201. package/test/fixtures/main-mjs/package.json +8 -0
  202. package/test/fixtures/module-a.js +1 -0
  203. package/test/fixtures/module-b.js +1 -0
  204. package/test/fixtures/plugins/local-plugin.js +7 -0
  205. package/test/fixtures/plugins/node_modules/atlaspack-transformer-bad-engines/index.js +7 -0
  206. package/test/fixtures/plugins/node_modules/atlaspack-transformer-bad-engines/package.json +7 -0
  207. package/test/fixtures/plugins/node_modules/atlaspack-transformer-no-engines/index.js +7 -0
  208. package/test/fixtures/plugins/node_modules/atlaspack-transformer-no-engines/package.json +4 -0
  209. package/test/fixtures/targets-default-distdir-none/package.json +5 -0
  210. package/test/fixtures/targets-default-distdir-one/package.json +8 -0
  211. package/test/fixtures/targets-default-distdir-two/package.json +18 -0
  212. package/test/requests/ConfigRequest.test.js +254 -0
  213. package/test/serializer.test.js +302 -0
  214. package/test/test-utils.js +80 -0
  215. package/test/utils.test.js +43 -0
@@ -0,0 +1,142 @@
1
+ // @flow strict-local
2
+
3
+ import type {InitialAtlaspackOptions} from '@atlaspack/types';
4
+ import WorkerFarm from '@atlaspack/workers';
5
+ // flowlint-next-line untyped-import:off
6
+ import sinon from 'sinon';
7
+ import assert from 'assert';
8
+ import path from 'path';
9
+ import Atlaspack, {createWorkerFarm} from '../src/Atlaspack';
10
+
11
+ describe('Atlaspack', function () {
12
+ this.timeout(75000);
13
+
14
+ let workerFarm;
15
+ before(() => {
16
+ workerFarm = createWorkerFarm();
17
+ });
18
+
19
+ after(() => workerFarm.end());
20
+
21
+ it('does not initialize when passed an ending farm', async () => {
22
+ workerFarm.ending = true;
23
+ let atlaspack = createAtlaspack({workerFarm});
24
+
25
+ // $FlowFixMe
26
+ await assert.rejects(() => atlaspack.run(), {
27
+ name: 'Error',
28
+ message: 'Supplied WorkerFarm is ending',
29
+ });
30
+
31
+ workerFarm.ending = false;
32
+ });
33
+
34
+ describe('atlaspack.end()', () => {
35
+ let endSpy;
36
+ beforeEach(() => {
37
+ endSpy = sinon.spy(WorkerFarm.prototype, 'end');
38
+ });
39
+
40
+ afterEach(() => {
41
+ endSpy.restore();
42
+ });
43
+
44
+ it('ends any WorkerFarm it creates', async () => {
45
+ let atlaspack = createAtlaspack();
46
+ await atlaspack.run();
47
+ assert.equal(endSpy.callCount, 1);
48
+ });
49
+
50
+ it('runs and constructs another farm for subsequent builds', async () => {
51
+ let atlaspack = createAtlaspack();
52
+
53
+ await atlaspack.run();
54
+ await atlaspack.run();
55
+
56
+ assert.equal(endSpy.callCount, 2);
57
+ });
58
+
59
+ it('does not end passed WorkerFarms', async () => {
60
+ let atlaspack = createAtlaspack({workerFarm});
61
+ await atlaspack.run();
62
+ assert.equal(endSpy.callCount, 0);
63
+
64
+ await workerFarm.end();
65
+ });
66
+
67
+ it('removes shared references it creates', async () => {
68
+ let atlaspack = createAtlaspack({workerFarm});
69
+ await atlaspack.run();
70
+
71
+ assert.equal(workerFarm.sharedReferences.size, 0);
72
+ assert.equal(workerFarm.sharedReferencesByValue.size, 0);
73
+ await workerFarm.end();
74
+ });
75
+ });
76
+ });
77
+
78
+ describe('AtlaspackAPI', function () {
79
+ this.timeout(75000);
80
+
81
+ let workerFarm;
82
+ beforeEach(() => {
83
+ workerFarm = createWorkerFarm();
84
+ });
85
+
86
+ afterEach(() => workerFarm.end());
87
+
88
+ describe('atlaspack.unstable_transform()', () => {
89
+ it('should transform simple file', async () => {
90
+ let atlaspack = createAtlaspack({workerFarm});
91
+ let res = await atlaspack.unstable_transform({
92
+ filePath: path.join(__dirname, 'fixtures/atlaspack/index.js'),
93
+ });
94
+ let code = await res[0].getCode();
95
+ assert(code.includes(`exports.default = 'test'`));
96
+ });
97
+
98
+ it('should transform with standalone mode', async () => {
99
+ let atlaspack = createAtlaspack({workerFarm});
100
+ let res = await atlaspack.unstable_transform({
101
+ filePath: path.join(__dirname, 'fixtures/atlaspack/other.js'),
102
+ query: 'standalone=true',
103
+ });
104
+ let code = await res[0].getCode();
105
+
106
+ assert(code.includes(`require("./index.js")`));
107
+ assert(code.includes(`new URL("index.js", "file:" + __filename);`));
108
+ assert(code.includes(`import('index.js')`));
109
+ });
110
+ });
111
+
112
+ describe('atlaspack.resolve()', () => {
113
+ it('should resolve dependencies', async () => {
114
+ let atlaspack = createAtlaspack({workerFarm});
115
+ let res = await atlaspack.unstable_resolve({
116
+ specifier: './other',
117
+ specifierType: 'esm',
118
+ resolveFrom: path.join(__dirname, 'fixtures/atlaspack/index.js'),
119
+ });
120
+
121
+ assert.deepEqual(res, {
122
+ filePath: path.join(__dirname, 'fixtures/atlaspack/other.js'),
123
+ code: undefined,
124
+ query: undefined,
125
+ sideEffects: true,
126
+ });
127
+ });
128
+ });
129
+ });
130
+
131
+ function createAtlaspack(opts?: InitialAtlaspackOptions) {
132
+ return new Atlaspack({
133
+ entries: [path.join(__dirname, 'fixtures/atlaspack/index.js')],
134
+ logLevel: 'info',
135
+ defaultConfig: path.join(
136
+ path.dirname(require.resolve('@atlaspack/test-utils')),
137
+ '.atlaspackrc-no-reporters',
138
+ ),
139
+ shouldDisableCache: true,
140
+ ...opts,
141
+ });
142
+ }
@@ -0,0 +1,405 @@
1
+ // @flow strict-local
2
+
3
+ import AtlaspackConfig from '../src/AtlaspackConfig';
4
+ import assert from 'assert';
5
+ import path from 'path';
6
+ import sinon from 'sinon';
7
+ import logger from '@atlaspack/logger';
8
+ import {inputFS} from '@atlaspack/test-utils';
9
+ import {parseAndProcessConfig} from '../src/requests/AtlaspackConfigRequest';
10
+ import {DEFAULT_OPTIONS} from './test-utils';
11
+ import {toProjectPath} from '../src/projectPath';
12
+
13
+ const ATLASPACKRC_PATH = toProjectPath('/', '/.atlaspackrc');
14
+
15
+ describe('AtlaspackConfig', () => {
16
+ describe('matchGlobMap', () => {
17
+ let config = new AtlaspackConfig(
18
+ {
19
+ filePath: ATLASPACKRC_PATH,
20
+ bundler: undefined,
21
+ packagers: {
22
+ '*.css': {
23
+ packageName: 'atlaspack-packager-css',
24
+ resolveFrom: ATLASPACKRC_PATH,
25
+ keyPath: '/packagers/*.css',
26
+ },
27
+ '*.js': {
28
+ packageName: 'atlaspack-packager-js',
29
+ resolveFrom: ATLASPACKRC_PATH,
30
+ keyPath: '/packagers/*.js',
31
+ },
32
+ },
33
+ },
34
+ DEFAULT_OPTIONS,
35
+ );
36
+
37
+ it('should return null array if no glob matches', () => {
38
+ let result = config.matchGlobMap(
39
+ toProjectPath('/', '/foo.wasm'),
40
+ config.packagers,
41
+ );
42
+ assert.deepEqual(result, null);
43
+ });
44
+
45
+ it('should return a matching pipeline', () => {
46
+ let result = config.matchGlobMap(
47
+ toProjectPath('/', '/foo.js'),
48
+ config.packagers,
49
+ );
50
+ assert.deepEqual(result, {
51
+ packageName: 'atlaspack-packager-js',
52
+ resolveFrom: ATLASPACKRC_PATH,
53
+ keyPath: '/packagers/*.js',
54
+ });
55
+ });
56
+ });
57
+
58
+ describe('matchGlobMapPipelines', () => {
59
+ let config = new AtlaspackConfig(
60
+ {
61
+ filePath: ATLASPACKRC_PATH,
62
+ bundler: undefined,
63
+ transformers: {
64
+ '*.jsx': [
65
+ {
66
+ packageName: 'atlaspack-transform-jsx',
67
+ resolveFrom: ATLASPACKRC_PATH,
68
+ keyPath: '/transformers/*.jsx/0',
69
+ },
70
+ '...',
71
+ ],
72
+ '*.{js,jsx}': [
73
+ {
74
+ packageName: 'atlaspack-transform-js',
75
+ resolveFrom: ATLASPACKRC_PATH,
76
+ keyPath: '/transformers/*.{js,jsx}/0',
77
+ },
78
+ ],
79
+ },
80
+ },
81
+ DEFAULT_OPTIONS,
82
+ );
83
+
84
+ it('should return an empty array if no pipeline matches', () => {
85
+ let pipeline = config.matchGlobMapPipelines(
86
+ toProjectPath('/', '/foo.css'),
87
+ config.transformers,
88
+ );
89
+ assert.deepEqual(pipeline, []);
90
+ });
91
+
92
+ it('should return a matching pipeline', () => {
93
+ let pipeline = config.matchGlobMapPipelines(
94
+ toProjectPath('/', '/foo.js'),
95
+ config.transformers,
96
+ );
97
+ assert.deepEqual(pipeline, [
98
+ {
99
+ packageName: 'atlaspack-transform-js',
100
+ resolveFrom: ATLASPACKRC_PATH,
101
+ keyPath: '/transformers/*.{js,jsx}/0',
102
+ },
103
+ ]);
104
+ });
105
+
106
+ it('should merge pipelines with spread elements', () => {
107
+ let pipeline = config.matchGlobMapPipelines(
108
+ toProjectPath('/', '/foo.jsx'),
109
+ config.transformers,
110
+ );
111
+ assert.deepEqual(pipeline, [
112
+ {
113
+ packageName: 'atlaspack-transform-jsx',
114
+ resolveFrom: ATLASPACKRC_PATH,
115
+ keyPath: '/transformers/*.jsx/0',
116
+ },
117
+ {
118
+ packageName: 'atlaspack-transform-js',
119
+ resolveFrom: ATLASPACKRC_PATH,
120
+ keyPath: '/transformers/*.{js,jsx}/0',
121
+ },
122
+ ]);
123
+ });
124
+ });
125
+
126
+ describe('loadPlugin', () => {
127
+ it('should warn if a plugin needs to specify an engines.atlaspack field in package.json', async () => {
128
+ let projectRoot = path.join(__dirname, 'fixtures', 'plugins');
129
+ let configFilePath = toProjectPath(
130
+ projectRoot,
131
+ path.join(__dirname, 'fixtures', 'plugins', '.atlaspackrc'),
132
+ );
133
+ let config = new AtlaspackConfig(
134
+ {
135
+ filePath: configFilePath,
136
+ bundler: undefined,
137
+ transformers: {
138
+ '*.js': [
139
+ {
140
+ packageName: 'atlaspack-transformer-no-engines',
141
+ resolveFrom: configFilePath,
142
+ keyPath: '/transformers/*.js/0',
143
+ },
144
+ ],
145
+ },
146
+ },
147
+ {...DEFAULT_OPTIONS, projectRoot},
148
+ );
149
+
150
+ let warnStub = sinon.stub(logger, 'warn');
151
+ let {plugin} = await config.loadPlugin({
152
+ packageName: 'atlaspack-transformer-no-engines',
153
+ resolveFrom: configFilePath,
154
+ keyPath: '/transformers/*.js/0',
155
+ });
156
+ assert(plugin);
157
+ assert.equal(typeof plugin.transform, 'function');
158
+ assert(warnStub.calledOnce);
159
+ assert.deepEqual(warnStub.getCall(0).args[0], {
160
+ origin: '@atlaspack/core',
161
+ message:
162
+ 'The plugin "atlaspack-transformer-no-engines" needs to specify a `package.json#engines.atlaspack` field with the supported Atlaspack version range.',
163
+ });
164
+ warnStub.restore();
165
+ });
166
+
167
+ it('should error if a plugin specifies an invalid engines.atlaspack field in package.json', async () => {
168
+ let projectRoot = path.join(__dirname, 'fixtures', 'plugins');
169
+ let configFilePath = toProjectPath(
170
+ projectRoot,
171
+ path.join(__dirname, 'fixtures', 'plugins', '.atlaspackrc'),
172
+ );
173
+ let config = new AtlaspackConfig(
174
+ {
175
+ filePath: configFilePath,
176
+ bundler: undefined,
177
+ transformers: {
178
+ '*.js': [
179
+ {
180
+ packageName: 'atlaspack-transformer-not-found',
181
+ resolveFrom: configFilePath,
182
+ keyPath: '/transformers/*.js/0',
183
+ },
184
+ ],
185
+ },
186
+ },
187
+ {...DEFAULT_OPTIONS, projectRoot},
188
+ );
189
+ // $FlowFixMe[untyped-import]
190
+ let atlaspackVersion = require('../package.json').version;
191
+ let pkgJSON = path.join(
192
+ __dirname,
193
+ 'fixtures',
194
+ 'plugins',
195
+ 'node_modules',
196
+ 'atlaspack-transformer-bad-engines',
197
+ 'package.json',
198
+ );
199
+ let code = inputFS.readFileSync(pkgJSON, 'utf8');
200
+
201
+ // $FlowFixMe
202
+ await assert.rejects(
203
+ () =>
204
+ config.loadPlugin({
205
+ packageName: 'atlaspack-transformer-bad-engines',
206
+ resolveFrom: configFilePath,
207
+ keyPath: '/transformers/*.js/0',
208
+ }),
209
+ {
210
+ name: 'Error',
211
+ diagnostics: [
212
+ {
213
+ message: `The plugin "atlaspack-transformer-bad-engines" is not compatible with the current version of Atlaspack. Requires "5.x" but the current version is "${atlaspackVersion}".`,
214
+ origin: '@atlaspack/core',
215
+ codeFrames: [
216
+ {
217
+ filePath: pkgJSON,
218
+ language: 'json5',
219
+ code,
220
+ codeHighlights: [
221
+ {
222
+ start: {line: 5, column: 5},
223
+ end: {line: 5, column: 22},
224
+ message: undefined,
225
+ },
226
+ ],
227
+ },
228
+ ],
229
+ },
230
+ ],
231
+ },
232
+ );
233
+ });
234
+
235
+ it('should error with a codeframe if a plugin is not resolved', async () => {
236
+ let configFilePath = path.join(
237
+ __dirname,
238
+ 'fixtures',
239
+ 'config-plugin-not-found',
240
+ '.atlaspackrc',
241
+ );
242
+ let code = await DEFAULT_OPTIONS.inputFS.readFile(configFilePath, 'utf8');
243
+ let {config} = await parseAndProcessConfig(
244
+ configFilePath,
245
+ code,
246
+ DEFAULT_OPTIONS,
247
+ );
248
+ let atlaspackConfig = new AtlaspackConfig(config, DEFAULT_OPTIONS);
249
+
250
+ // $FlowFixMe
251
+ await assert.rejects(() => atlaspackConfig.getTransformers('test.js'), {
252
+ name: 'Error',
253
+ diagnostics: [
254
+ {
255
+ message: 'Cannot find Atlaspack plugin "@atlaspack/transformer-jj"',
256
+ origin: '@atlaspack/core',
257
+ codeFrames: [
258
+ {
259
+ filePath: configFilePath,
260
+ language: 'json5',
261
+ code,
262
+ codeHighlights: [
263
+ {
264
+ start: {line: 4, column: 14},
265
+ end: {line: 4, column: 40},
266
+ message: `Cannot find module "@atlaspack/transformer-jj", did you mean "@atlaspack/transformer-js"?`,
267
+ },
268
+ ],
269
+ },
270
+ ],
271
+ },
272
+ ],
273
+ });
274
+ });
275
+
276
+ it('should error when using a reserved pipeline name "node:*"', async () => {
277
+ let configFilePath = path.join(
278
+ __dirname,
279
+ 'fixtures',
280
+ 'config-node-pipeline',
281
+ '.atlaspackrc',
282
+ );
283
+ let code = await DEFAULT_OPTIONS.inputFS.readFile(configFilePath, 'utf8');
284
+
285
+ // $FlowFixMe
286
+ await assert.rejects(
287
+ () => parseAndProcessConfig(configFilePath, code, DEFAULT_OPTIONS),
288
+ {
289
+ name: 'Error',
290
+ diagnostics: [
291
+ {
292
+ message: "Named pipeline 'node:' is reserved.",
293
+ origin: '@atlaspack/core',
294
+ codeFrames: [
295
+ {
296
+ filePath: configFilePath,
297
+ language: 'json5',
298
+ code,
299
+ codeHighlights: [
300
+ {
301
+ message: undefined,
302
+ start: {
303
+ line: 4,
304
+ column: 5,
305
+ },
306
+ end: {
307
+ line: 4,
308
+ column: 15,
309
+ },
310
+ },
311
+ ],
312
+ },
313
+ ],
314
+ documentationURL:
315
+ 'https://parceljs.org/features/dependency-resolution/#url-schemes',
316
+ },
317
+ ],
318
+ },
319
+ );
320
+ });
321
+
322
+ it('should support loading local plugins', async () => {
323
+ let projectRoot = path.join(__dirname, 'fixtures', 'plugins');
324
+ let configFilePath = toProjectPath(
325
+ projectRoot,
326
+ path.join(__dirname, 'fixtures', 'plugins', '.atlaspackrc'),
327
+ );
328
+ let config = new AtlaspackConfig(
329
+ {
330
+ filePath: configFilePath,
331
+ bundler: undefined,
332
+ transformers: {
333
+ '*.js': [
334
+ {
335
+ packageName: './local-plugin',
336
+ resolveFrom: configFilePath,
337
+ keyPath: '/transformers/*.js/0',
338
+ },
339
+ ],
340
+ },
341
+ },
342
+ {...DEFAULT_OPTIONS, projectRoot},
343
+ );
344
+
345
+ let [{plugin}] = await config.getTransformers(
346
+ toProjectPath('/', '/foo.js'),
347
+ );
348
+ assert(plugin);
349
+ assert.equal(typeof plugin.transform, 'function');
350
+ });
351
+
352
+ it('should error on local plugins inside config packages', async () => {
353
+ let configFilePath = path.join(
354
+ __dirname,
355
+ 'fixtures',
356
+ 'local-plugin-config-pkg',
357
+ '.atlaspackrc',
358
+ );
359
+ let code = await DEFAULT_OPTIONS.inputFS.readFile(configFilePath, 'utf8');
360
+ let {config} = await parseAndProcessConfig(
361
+ configFilePath,
362
+ code,
363
+ DEFAULT_OPTIONS,
364
+ );
365
+ let atlaspackConfig = new AtlaspackConfig(config, DEFAULT_OPTIONS);
366
+ let extendedConfigPath = path.join(
367
+ __dirname,
368
+ 'fixtures',
369
+ 'local-plugin-config-pkg',
370
+ 'node_modules',
371
+ 'atlaspack-config-local',
372
+ 'index.json',
373
+ );
374
+
375
+ // $FlowFixMe
376
+ await assert.rejects(() => atlaspackConfig.getTransformers('test.js'), {
377
+ name: 'Error',
378
+ diagnostics: [
379
+ {
380
+ message:
381
+ 'Local plugins are not supported in Atlaspack config packages. Please publish "./local-plugin" as a separate npm package.',
382
+ origin: '@atlaspack/core',
383
+ codeFrames: [
384
+ {
385
+ filePath: extendedConfigPath,
386
+ language: 'json5',
387
+ code: await DEFAULT_OPTIONS.inputFS.readFile(
388
+ extendedConfigPath,
389
+ 'utf8',
390
+ ),
391
+ codeHighlights: [
392
+ {
393
+ start: {line: 5, column: 7},
394
+ end: {line: 5, column: 22},
395
+ message: undefined,
396
+ },
397
+ ],
398
+ },
399
+ ],
400
+ },
401
+ ],
402
+ });
403
+ });
404
+ });
405
+ });