@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.
- package/LICENSE +201 -0
- package/index.d.ts +22 -0
- package/lib/AssetGraph.js +518 -0
- package/lib/Atlaspack.js +587 -0
- package/lib/AtlaspackConfig.js +298 -0
- package/lib/AtlaspackConfig.schema.js +125 -0
- package/lib/BundleGraph.js +1445 -0
- package/lib/CommittedAsset.js +133 -0
- package/lib/Dependency.js +88 -0
- package/lib/Environment.js +128 -0
- package/lib/InternalConfig.js +48 -0
- package/lib/PackagerRunner.js +519 -0
- package/lib/ReporterRunner.js +151 -0
- package/lib/RequestTracker.js +1089 -0
- package/lib/SymbolPropagation.js +625 -0
- package/lib/TargetDescriptor.schema.js +115 -0
- package/lib/Transformation.js +536 -0
- package/lib/UncommittedAsset.js +342 -0
- package/lib/Validation.js +215 -0
- package/lib/applyRuntimes.js +279 -0
- package/lib/assetUtils.js +189 -0
- package/lib/atlaspack-v3/AtlaspackV3.js +74 -0
- package/lib/atlaspack-v3/fs.js +30 -0
- package/lib/atlaspack-v3/index.js +19 -0
- package/lib/atlaspack-v3/jsCallable.js +15 -0
- package/lib/atlaspack-v3/plugins/Resolver.js +12 -0
- package/lib/atlaspack-v3/plugins/index.js +16 -0
- package/lib/atlaspack-v3/worker/index.js +3 -0
- package/lib/atlaspack-v3/worker/worker.js +30 -0
- package/lib/buildCache.js +18 -0
- package/lib/constants.js +21 -0
- package/lib/dumpGraphToGraphViz.js +206 -0
- package/lib/index.js +106 -0
- package/lib/loadAtlaspackPlugin.js +148 -0
- package/lib/loadDotEnv.js +54 -0
- package/lib/projectPath.js +86 -0
- package/lib/public/Asset.js +259 -0
- package/lib/public/Bundle.js +231 -0
- package/lib/public/BundleGraph.js +193 -0
- package/lib/public/BundleGroup.js +44 -0
- package/lib/public/Config.js +202 -0
- package/lib/public/Dependency.js +131 -0
- package/lib/public/Environment.js +244 -0
- package/lib/public/MutableBundleGraph.js +184 -0
- package/lib/public/PluginOptions.js +71 -0
- package/lib/public/Symbols.js +247 -0
- package/lib/public/Target.js +64 -0
- package/lib/registerCoreWithSerializer.js +45 -0
- package/lib/requests/AssetGraphRequest.js +427 -0
- package/lib/requests/AssetGraphRequestRust.js +187 -0
- package/lib/requests/AssetRequest.js +137 -0
- package/lib/requests/AtlaspackBuildRequest.js +78 -0
- package/lib/requests/AtlaspackConfigRequest.js +473 -0
- package/lib/requests/BundleGraphRequest.js +419 -0
- package/lib/requests/ConfigRequest.js +198 -0
- package/lib/requests/DevDepRequest.js +166 -0
- package/lib/requests/EntryRequest.js +295 -0
- package/lib/requests/PackageRequest.js +88 -0
- package/lib/requests/PathRequest.js +349 -0
- package/lib/requests/TargetRequest.js +1177 -0
- package/lib/requests/ValidationRequest.js +66 -0
- package/lib/requests/WriteBundleRequest.js +252 -0
- package/lib/requests/WriteBundlesRequest.js +153 -0
- package/lib/resolveOptions.js +234 -0
- package/lib/serializer.js +216 -0
- package/lib/serializerCore.browser.js +29 -0
- package/lib/serializerCore.js +16 -0
- package/lib/summarizeRequest.js +55 -0
- package/lib/types.js +35 -0
- package/lib/utils.js +160 -0
- package/lib/worker.js +170 -0
- package/package.json +59 -0
- package/src/AssetGraph.js +646 -0
- package/src/Atlaspack.js +632 -0
- package/src/AtlaspackConfig.js +490 -0
- package/src/AtlaspackConfig.schema.js +141 -0
- package/src/BundleGraph.js +2193 -0
- package/src/CommittedAsset.js +143 -0
- package/src/Dependency.js +142 -0
- package/src/Environment.js +151 -0
- package/src/InternalConfig.js +72 -0
- package/src/PackagerRunner.js +790 -0
- package/src/ReporterRunner.js +158 -0
- package/src/RequestTracker.js +1697 -0
- package/src/SymbolPropagation.js +794 -0
- package/src/TargetDescriptor.schema.js +136 -0
- package/src/Transformation.js +752 -0
- package/src/UncommittedAsset.js +426 -0
- package/src/Validation.js +223 -0
- package/src/applyRuntimes.js +341 -0
- package/src/assetUtils.js +254 -0
- package/src/atlaspack-v3/AtlaspackV3.js +73 -0
- package/src/atlaspack-v3/fs.js +36 -0
- package/src/atlaspack-v3/index.js +5 -0
- package/src/atlaspack-v3/jsCallable.js +13 -0
- package/src/atlaspack-v3/plugins/Resolver.js +9 -0
- package/src/atlaspack-v3/plugins/index.js +3 -0
- package/src/atlaspack-v3/worker/index.js +8 -0
- package/src/atlaspack-v3/worker/worker.js +14 -0
- package/src/buildCache.js +15 -0
- package/src/constants.js +22 -0
- package/src/dumpGraphToGraphViz.js +244 -0
- package/src/index.js +22 -0
- package/src/loadAtlaspackPlugin.js +239 -0
- package/src/loadDotEnv.js +56 -0
- package/src/projectPath.js +87 -0
- package/src/public/Asset.js +359 -0
- package/src/public/Bundle.js +337 -0
- package/src/public/BundleGraph.js +335 -0
- package/src/public/BundleGroup.js +55 -0
- package/src/public/Config.js +261 -0
- package/src/public/Dependency.js +176 -0
- package/src/public/Environment.js +316 -0
- package/src/public/MutableBundleGraph.js +320 -0
- package/src/public/PluginOptions.js +99 -0
- package/src/public/Symbols.js +315 -0
- package/src/public/Target.js +71 -0
- package/src/registerCoreWithSerializer.js +34 -0
- package/src/requests/AssetGraphRequest.js +577 -0
- package/src/requests/AssetGraphRequestRust.js +222 -0
- package/src/requests/AssetRequest.js +179 -0
- package/src/requests/AtlaspackBuildRequest.js +109 -0
- package/src/requests/AtlaspackConfigRequest.js +709 -0
- package/src/requests/BundleGraphRequest.js +547 -0
- package/src/requests/ConfigRequest.js +287 -0
- package/src/requests/DevDepRequest.js +246 -0
- package/src/requests/EntryRequest.js +385 -0
- package/src/requests/PackageRequest.js +105 -0
- package/src/requests/PathRequest.js +454 -0
- package/src/requests/TargetRequest.js +1632 -0
- package/src/requests/ValidationRequest.js +79 -0
- package/src/requests/WriteBundleRequest.js +362 -0
- package/src/requests/WriteBundlesRequest.js +209 -0
- package/src/resolveOptions.js +278 -0
- package/src/serializer.js +255 -0
- package/src/serializerCore.browser.js +8 -0
- package/src/serializerCore.js +5 -0
- package/src/summarizeRequest.js +47 -0
- package/src/types.js +581 -0
- package/src/utils.js +211 -0
- package/src/worker.js +189 -0
- package/test/AssetGraph.test.js +679 -0
- package/test/Atlaspack.test.js +142 -0
- package/test/AtlaspackConfig.test.js +405 -0
- package/test/AtlaspackConfigRequest.test.js +993 -0
- package/test/BundleGraph.test.js +121 -0
- package/test/EntryRequest.test.js +215 -0
- package/test/Environment.test.js +99 -0
- package/test/InternalAsset.test.js +76 -0
- package/test/PackagerRunner.test.js +27 -0
- package/test/PublicAsset.test.js +40 -0
- package/test/PublicBundle.test.js +68 -0
- package/test/PublicDependency.test.js +22 -0
- package/test/PublicEnvironment.test.js +27 -0
- package/test/PublicMutableBundleGraph.test.js +192 -0
- package/test/RequestTracker.test.js +448 -0
- package/test/SymbolPropagation.test.js +716 -0
- package/test/TargetRequest.test.js +1715 -0
- package/test/fixtures/application-targets/package.json +3 -0
- package/test/fixtures/atlaspack/index.js +1 -0
- package/test/fixtures/atlaspack/other.js +3 -0
- package/test/fixtures/atlaspack/package.json +1 -0
- package/test/fixtures/atlaspack/yarn.lock +0 -0
- package/test/fixtures/bundle.js +10 -0
- package/test/fixtures/common-targets/package.json +24 -0
- package/test/fixtures/common-targets-ignore/package.json +13 -0
- package/test/fixtures/config/.atlaspackrc +6 -0
- package/test/fixtures/config/subfolder/.atlaspackrc +6 -0
- package/test/fixtures/config-extends-not-found/.atlaspackrc +3 -0
- package/test/fixtures/config-extends-not-found/.atlaspackrc-json5 +3 -0
- package/test/fixtures/config-extends-not-found/.atlaspackrc-multiple +3 -0
- package/test/fixtures/config-extends-not-found/.atlaspackrc-node-modules +3 -0
- package/test/fixtures/config-malformed/.atlaspackrc +3 -0
- package/test/fixtures/config-node-pipeline/.atlaspackrc +6 -0
- package/test/fixtures/config-plugin-not-found/.atlaspackrc +6 -0
- package/test/fixtures/context/package.json +8 -0
- package/test/fixtures/custom-format-infer-ext/package.json +6 -0
- package/test/fixtures/custom-format-infer-type/package.json +7 -0
- package/test/fixtures/custom-format-mismatch/package.json +8 -0
- package/test/fixtures/custom-targets/package.json +20 -0
- package/test/fixtures/custom-targets-distdir/package.json +11 -0
- package/test/fixtures/duplicate-targets/package.json +4 -0
- package/test/fixtures/glob-like/[entry].js +0 -0
- package/test/fixtures/invalid-distpath/package.json +11 -0
- package/test/fixtures/invalid-engines/package.json +12 -0
- package/test/fixtures/invalid-source-missing/package.json +5 -0
- package/test/fixtures/invalid-source-not-file/package.json +5 -0
- package/test/fixtures/invalid-source-not-file/src/index.js +1 -0
- package/test/fixtures/invalid-target-source-missing/package.json +9 -0
- package/test/fixtures/invalid-target-source-not-file/package.json +9 -0
- package/test/fixtures/invalid-target-source-not-file/src/index.js +1 -0
- package/test/fixtures/invalid-targets/package.json +19 -0
- package/test/fixtures/library-custom-scopehoist/package.json +9 -0
- package/test/fixtures/library-scopehoist/package.json +8 -0
- package/test/fixtures/local-plugin-config-pkg/.atlaspackrc +3 -0
- package/test/fixtures/local-plugin-config-pkg/node_modules/atlaspack-config-local/index.json +8 -0
- package/test/fixtures/local-plugin-config-pkg/node_modules/atlaspack-config-local/local-plugin.js +7 -0
- package/test/fixtures/local-plugin-config-pkg/node_modules/atlaspack-config-local/package.json +7 -0
- package/test/fixtures/main-format-mismatch/package.json +8 -0
- package/test/fixtures/main-global/package.json +8 -0
- package/test/fixtures/main-mjs/package.json +8 -0
- package/test/fixtures/module-a.js +1 -0
- package/test/fixtures/module-b.js +1 -0
- package/test/fixtures/plugins/local-plugin.js +7 -0
- package/test/fixtures/plugins/node_modules/atlaspack-transformer-bad-engines/index.js +7 -0
- package/test/fixtures/plugins/node_modules/atlaspack-transformer-bad-engines/package.json +7 -0
- package/test/fixtures/plugins/node_modules/atlaspack-transformer-no-engines/index.js +7 -0
- package/test/fixtures/plugins/node_modules/atlaspack-transformer-no-engines/package.json +4 -0
- package/test/fixtures/targets-default-distdir-none/package.json +5 -0
- package/test/fixtures/targets-default-distdir-one/package.json +8 -0
- package/test/fixtures/targets-default-distdir-two/package.json +18 -0
- package/test/requests/ConfigRequest.test.js +254 -0
- package/test/serializer.test.js +302 -0
- package/test/test-utils.js +80 -0
- package/test/utils.test.js +43 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// @flow strict-local
|
|
2
|
+
|
|
3
|
+
import assert from 'assert';
|
|
4
|
+
import BundleGraph from '../src/BundleGraph';
|
|
5
|
+
import {DEFAULT_ENV, DEFAULT_TARGETS} from './test-utils';
|
|
6
|
+
import AssetGraph, {nodeFromAssetGroup} from '../src/AssetGraph';
|
|
7
|
+
import {createAsset as _createAsset} from '../src/assetUtils';
|
|
8
|
+
import {createDependency as _createDependency} from '../src/Dependency';
|
|
9
|
+
import {toProjectPath} from '../src/projectPath';
|
|
10
|
+
|
|
11
|
+
function createAsset(opts) {
|
|
12
|
+
return _createAsset('/', opts);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function createDependency(opts) {
|
|
16
|
+
return _createDependency('/', opts);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const id1 = '0123456789abcdef0123456789abcdef';
|
|
20
|
+
const id2 = '9876543210fedcba9876543210fedcba';
|
|
21
|
+
|
|
22
|
+
describe('BundleGraph', () => {
|
|
23
|
+
it('assigns publicIds to assets', () => {
|
|
24
|
+
let bundleGraph = BundleGraph.fromAssetGraph(
|
|
25
|
+
createMockAssetGraph([id1, id2]),
|
|
26
|
+
false,
|
|
27
|
+
);
|
|
28
|
+
assert.deepEqual(
|
|
29
|
+
getAssets(bundleGraph).map(a => bundleGraph.getAssetPublicId(a)),
|
|
30
|
+
['296TI', '4DGUq'],
|
|
31
|
+
);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('uses a longer publicId if there is a collision', () => {
|
|
35
|
+
let bundleGraph = BundleGraph.fromAssetGraph(
|
|
36
|
+
createMockAssetGraph([id1, id1.slice(0, 16) + '7' + id1.slice(17)]),
|
|
37
|
+
false,
|
|
38
|
+
);
|
|
39
|
+
assert.deepEqual(
|
|
40
|
+
getAssets(bundleGraph).map(a => bundleGraph.getAssetPublicId(a)),
|
|
41
|
+
['296TI', '296TII'],
|
|
42
|
+
);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
function getAssets(bundleGraph) {
|
|
47
|
+
let assets = [];
|
|
48
|
+
bundleGraph.traverse(node => {
|
|
49
|
+
if (node.type === 'asset') {
|
|
50
|
+
assets.push(node.value);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
return assets;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const stats = {size: 0, time: 0};
|
|
57
|
+
function createMockAssetGraph(ids: [string, string]) {
|
|
58
|
+
let graph = new AssetGraph();
|
|
59
|
+
graph.setRootConnections({entries: [toProjectPath('/', '/index')]});
|
|
60
|
+
|
|
61
|
+
graph.resolveEntry(
|
|
62
|
+
toProjectPath('/', '/index'),
|
|
63
|
+
[
|
|
64
|
+
{
|
|
65
|
+
filePath: toProjectPath('/', '/path/to/index/src/main.js'),
|
|
66
|
+
packagePath: toProjectPath('/', '/path/to/index'),
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
'1',
|
|
70
|
+
);
|
|
71
|
+
graph.resolveTargets(
|
|
72
|
+
{
|
|
73
|
+
filePath: toProjectPath('/', '/path/to/index/src/main.js'),
|
|
74
|
+
packagePath: toProjectPath('/', '/path/to/index'),
|
|
75
|
+
},
|
|
76
|
+
DEFAULT_TARGETS,
|
|
77
|
+
'2',
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
let dep = createDependency({
|
|
81
|
+
specifier: 'path/to/index/src/main.js',
|
|
82
|
+
specifierType: 'esm',
|
|
83
|
+
env: DEFAULT_ENV,
|
|
84
|
+
target: DEFAULT_TARGETS[0],
|
|
85
|
+
});
|
|
86
|
+
let sourcePath = '/index.js';
|
|
87
|
+
let filePath = toProjectPath('/', sourcePath);
|
|
88
|
+
let req = {filePath, env: DEFAULT_ENV};
|
|
89
|
+
graph.resolveDependency(dep, nodeFromAssetGroup(req).value, '3');
|
|
90
|
+
|
|
91
|
+
let dep1 = createDependency({
|
|
92
|
+
specifier: 'dependent-asset-1',
|
|
93
|
+
specifierType: 'esm',
|
|
94
|
+
env: DEFAULT_ENV,
|
|
95
|
+
sourcePath,
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
let assets = [
|
|
99
|
+
createAsset({
|
|
100
|
+
id: ids[0],
|
|
101
|
+
filePath,
|
|
102
|
+
type: 'js',
|
|
103
|
+
isSource: true,
|
|
104
|
+
stats,
|
|
105
|
+
dependencies: new Map([['dep1', dep1]]),
|
|
106
|
+
env: DEFAULT_ENV,
|
|
107
|
+
}),
|
|
108
|
+
createAsset({
|
|
109
|
+
id: ids[1],
|
|
110
|
+
filePath,
|
|
111
|
+
type: 'js',
|
|
112
|
+
isSource: true,
|
|
113
|
+
stats,
|
|
114
|
+
dependencies: new Map([['dep1', dep1]]),
|
|
115
|
+
env: DEFAULT_ENV,
|
|
116
|
+
}),
|
|
117
|
+
];
|
|
118
|
+
graph.resolveAssetGroup(req, assets, '4');
|
|
119
|
+
|
|
120
|
+
return graph;
|
|
121
|
+
}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
// @flow strict-local
|
|
2
|
+
import assert from 'assert';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import {md} from '@atlaspack/diagnostic';
|
|
5
|
+
import {inputFS as fs} from '@atlaspack/test-utils';
|
|
6
|
+
import {EntryResolver} from '../src/requests/EntryRequest';
|
|
7
|
+
import {DEFAULT_OPTIONS as _DEFAULT_OPTIONS} from './test-utils';
|
|
8
|
+
|
|
9
|
+
const DEFAULT_OPTIONS = {
|
|
10
|
+
..._DEFAULT_OPTIONS,
|
|
11
|
+
defaultTargetOptions: {
|
|
12
|
+
..._DEFAULT_OPTIONS.defaultTargetOptions,
|
|
13
|
+
sourceMaps: true,
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const INVALID_SOURCE_MISSING_FIXTURE_PATH = path.join(
|
|
18
|
+
__dirname,
|
|
19
|
+
'fixtures/invalid-source-missing',
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
const INVALID_SOURCE_NOT_FILE_FIXTURE_PATH = path.join(
|
|
23
|
+
__dirname,
|
|
24
|
+
'fixtures/invalid-source-not-file',
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
const INVALID_TARGET_SOURCE_MISSING_FIXTURE_PATH = path.join(
|
|
28
|
+
__dirname,
|
|
29
|
+
'fixtures/invalid-target-source-missing',
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
const INVALID_TARGET_SOURCE_NOT_FILE_FIXTURE_PATH = path.join(
|
|
33
|
+
__dirname,
|
|
34
|
+
'fixtures/invalid-target-source-not-file',
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
const GLOB_LIKE_FIXTURE_PATH = path.join(
|
|
38
|
+
__dirname,
|
|
39
|
+
'fixtures/glob-like/[entry].js',
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
describe('EntryResolver', function () {
|
|
43
|
+
let entryResolver = new EntryResolver({...DEFAULT_OPTIONS});
|
|
44
|
+
|
|
45
|
+
it('rejects missing source in package.json', async function () {
|
|
46
|
+
this.timeout(10000);
|
|
47
|
+
// $FlowFixMe assert.rejects is Node 10+
|
|
48
|
+
await assert.rejects(
|
|
49
|
+
() => entryResolver.resolveEntry(INVALID_SOURCE_MISSING_FIXTURE_PATH),
|
|
50
|
+
{
|
|
51
|
+
diagnostics: [
|
|
52
|
+
{
|
|
53
|
+
origin: '@atlaspack/core',
|
|
54
|
+
message: md`${path.join(
|
|
55
|
+
path.relative(fs.cwd(), INVALID_SOURCE_MISSING_FIXTURE_PATH),
|
|
56
|
+
'missing.js',
|
|
57
|
+
)} does not exist.`,
|
|
58
|
+
codeFrames: [
|
|
59
|
+
{
|
|
60
|
+
filePath: path.join(
|
|
61
|
+
INVALID_SOURCE_MISSING_FIXTURE_PATH,
|
|
62
|
+
'package.json',
|
|
63
|
+
),
|
|
64
|
+
codeHighlights: [
|
|
65
|
+
{
|
|
66
|
+
message: undefined,
|
|
67
|
+
start: {
|
|
68
|
+
line: 4,
|
|
69
|
+
column: 13,
|
|
70
|
+
},
|
|
71
|
+
end: {
|
|
72
|
+
line: 4,
|
|
73
|
+
column: 24,
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
},
|
|
78
|
+
],
|
|
79
|
+
hints: [],
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
},
|
|
83
|
+
);
|
|
84
|
+
});
|
|
85
|
+
it('rejects non-file source in package.json', async function () {
|
|
86
|
+
this.timeout(10000);
|
|
87
|
+
// $FlowFixMe assert.rejects is Node 10+
|
|
88
|
+
await assert.rejects(
|
|
89
|
+
() => entryResolver.resolveEntry(INVALID_SOURCE_NOT_FILE_FIXTURE_PATH),
|
|
90
|
+
{
|
|
91
|
+
diagnostics: [
|
|
92
|
+
{
|
|
93
|
+
origin: '@atlaspack/core',
|
|
94
|
+
message: md`${path.join(
|
|
95
|
+
path.relative(fs.cwd(), INVALID_SOURCE_NOT_FILE_FIXTURE_PATH),
|
|
96
|
+
'src',
|
|
97
|
+
)} is not a file.`,
|
|
98
|
+
codeFrames: [
|
|
99
|
+
{
|
|
100
|
+
filePath: path.join(
|
|
101
|
+
INVALID_SOURCE_NOT_FILE_FIXTURE_PATH,
|
|
102
|
+
'package.json',
|
|
103
|
+
),
|
|
104
|
+
codeHighlights: [
|
|
105
|
+
{
|
|
106
|
+
message: undefined,
|
|
107
|
+
start: {
|
|
108
|
+
line: 4,
|
|
109
|
+
column: 13,
|
|
110
|
+
},
|
|
111
|
+
end: {
|
|
112
|
+
line: 4,
|
|
113
|
+
column: 17,
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
],
|
|
117
|
+
},
|
|
118
|
+
],
|
|
119
|
+
},
|
|
120
|
+
],
|
|
121
|
+
},
|
|
122
|
+
);
|
|
123
|
+
});
|
|
124
|
+
it('rejects missing target source in package.json', async function () {
|
|
125
|
+
this.timeout(10000);
|
|
126
|
+
// $FlowFixMe assert.rejects is Node 10+
|
|
127
|
+
await assert.rejects(
|
|
128
|
+
() =>
|
|
129
|
+
entryResolver.resolveEntry(INVALID_TARGET_SOURCE_MISSING_FIXTURE_PATH),
|
|
130
|
+
{
|
|
131
|
+
diagnostics: [
|
|
132
|
+
{
|
|
133
|
+
origin: '@atlaspack/core',
|
|
134
|
+
message: md`${path.join(
|
|
135
|
+
path.relative(
|
|
136
|
+
fs.cwd(),
|
|
137
|
+
INVALID_TARGET_SOURCE_MISSING_FIXTURE_PATH,
|
|
138
|
+
),
|
|
139
|
+
'missing.js',
|
|
140
|
+
)} does not exist.`,
|
|
141
|
+
codeFrames: [
|
|
142
|
+
{
|
|
143
|
+
filePath: path.join(
|
|
144
|
+
INVALID_TARGET_SOURCE_MISSING_FIXTURE_PATH,
|
|
145
|
+
'package.json',
|
|
146
|
+
),
|
|
147
|
+
codeHighlights: [
|
|
148
|
+
{
|
|
149
|
+
message: undefined,
|
|
150
|
+
start: {
|
|
151
|
+
line: 6,
|
|
152
|
+
column: 17,
|
|
153
|
+
},
|
|
154
|
+
end: {
|
|
155
|
+
line: 6,
|
|
156
|
+
column: 28,
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
],
|
|
160
|
+
},
|
|
161
|
+
],
|
|
162
|
+
hints: [],
|
|
163
|
+
},
|
|
164
|
+
],
|
|
165
|
+
},
|
|
166
|
+
);
|
|
167
|
+
});
|
|
168
|
+
it('rejects non-file target source in package.json', async function () {
|
|
169
|
+
this.timeout(10000);
|
|
170
|
+
// $FlowFixMe assert.rejects is Node 10+
|
|
171
|
+
await assert.rejects(
|
|
172
|
+
() =>
|
|
173
|
+
entryResolver.resolveEntry(INVALID_TARGET_SOURCE_NOT_FILE_FIXTURE_PATH),
|
|
174
|
+
{
|
|
175
|
+
diagnostics: [
|
|
176
|
+
{
|
|
177
|
+
origin: '@atlaspack/core',
|
|
178
|
+
message: md`${path.join(
|
|
179
|
+
path.relative(
|
|
180
|
+
fs.cwd(),
|
|
181
|
+
INVALID_TARGET_SOURCE_NOT_FILE_FIXTURE_PATH,
|
|
182
|
+
),
|
|
183
|
+
'src',
|
|
184
|
+
)} is not a file.`,
|
|
185
|
+
codeFrames: [
|
|
186
|
+
{
|
|
187
|
+
filePath: path.join(
|
|
188
|
+
INVALID_TARGET_SOURCE_NOT_FILE_FIXTURE_PATH,
|
|
189
|
+
'package.json',
|
|
190
|
+
),
|
|
191
|
+
codeHighlights: [
|
|
192
|
+
{
|
|
193
|
+
message: undefined,
|
|
194
|
+
start: {
|
|
195
|
+
line: 6,
|
|
196
|
+
column: 17,
|
|
197
|
+
},
|
|
198
|
+
end: {
|
|
199
|
+
line: 6,
|
|
200
|
+
column: 21,
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
],
|
|
204
|
+
},
|
|
205
|
+
],
|
|
206
|
+
},
|
|
207
|
+
],
|
|
208
|
+
},
|
|
209
|
+
);
|
|
210
|
+
});
|
|
211
|
+
it('does not time out on glob-like entry', async function () {
|
|
212
|
+
this.timeout(10000);
|
|
213
|
+
await entryResolver.resolveEntry(GLOB_LIKE_FIXTURE_PATH);
|
|
214
|
+
});
|
|
215
|
+
});
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// @flow strict-local
|
|
2
|
+
|
|
3
|
+
import assert from 'assert';
|
|
4
|
+
import {createEnvironment} from '../src/Environment';
|
|
5
|
+
|
|
6
|
+
describe('Environment', () => {
|
|
7
|
+
it('assigns a default environment with nothing passed', () => {
|
|
8
|
+
assert.deepEqual(createEnvironment(), {
|
|
9
|
+
id: 'c242f987e3544367',
|
|
10
|
+
context: 'browser',
|
|
11
|
+
engines: {
|
|
12
|
+
browsers: ['> 0.25%'],
|
|
13
|
+
},
|
|
14
|
+
includeNodeModules: true,
|
|
15
|
+
outputFormat: 'global',
|
|
16
|
+
isLibrary: false,
|
|
17
|
+
shouldOptimize: false,
|
|
18
|
+
shouldScopeHoist: false,
|
|
19
|
+
sourceMap: undefined,
|
|
20
|
+
loc: undefined,
|
|
21
|
+
sourceType: 'module',
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('assigns a node context if a node engine is given', () => {
|
|
26
|
+
assert.deepEqual(createEnvironment({engines: {node: '>= 10.0.0'}}), {
|
|
27
|
+
id: '69e0ab7220ee8f7a',
|
|
28
|
+
context: 'node',
|
|
29
|
+
engines: {
|
|
30
|
+
node: '>= 10.0.0',
|
|
31
|
+
},
|
|
32
|
+
includeNodeModules: false,
|
|
33
|
+
outputFormat: 'commonjs',
|
|
34
|
+
isLibrary: false,
|
|
35
|
+
shouldOptimize: false,
|
|
36
|
+
shouldScopeHoist: false,
|
|
37
|
+
sourceMap: undefined,
|
|
38
|
+
loc: undefined,
|
|
39
|
+
sourceType: 'module',
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('assigns a browser context if browser engines are given', () => {
|
|
44
|
+
assert.deepEqual(
|
|
45
|
+
createEnvironment({engines: {browsers: ['last 1 version']}}),
|
|
46
|
+
{
|
|
47
|
+
id: '4b5c9005af8c5b19',
|
|
48
|
+
context: 'browser',
|
|
49
|
+
engines: {
|
|
50
|
+
browsers: ['last 1 version'],
|
|
51
|
+
},
|
|
52
|
+
includeNodeModules: true,
|
|
53
|
+
outputFormat: 'global',
|
|
54
|
+
isLibrary: false,
|
|
55
|
+
shouldOptimize: false,
|
|
56
|
+
shouldScopeHoist: false,
|
|
57
|
+
sourceMap: undefined,
|
|
58
|
+
loc: undefined,
|
|
59
|
+
sourceType: 'module',
|
|
60
|
+
},
|
|
61
|
+
);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('assigns default engines for node', () => {
|
|
65
|
+
assert.deepEqual(createEnvironment({context: 'node'}), {
|
|
66
|
+
id: 'f7c9644283a8698f',
|
|
67
|
+
context: 'node',
|
|
68
|
+
engines: {
|
|
69
|
+
node: '>= 8.0.0',
|
|
70
|
+
},
|
|
71
|
+
includeNodeModules: false,
|
|
72
|
+
outputFormat: 'commonjs',
|
|
73
|
+
isLibrary: false,
|
|
74
|
+
shouldOptimize: false,
|
|
75
|
+
shouldScopeHoist: false,
|
|
76
|
+
sourceMap: undefined,
|
|
77
|
+
loc: undefined,
|
|
78
|
+
sourceType: 'module',
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('assigns default engines for browsers', () => {
|
|
83
|
+
assert.deepEqual(createEnvironment({context: 'browser'}), {
|
|
84
|
+
id: 'c242f987e3544367',
|
|
85
|
+
context: 'browser',
|
|
86
|
+
engines: {
|
|
87
|
+
browsers: ['> 0.25%'],
|
|
88
|
+
},
|
|
89
|
+
includeNodeModules: true,
|
|
90
|
+
outputFormat: 'global',
|
|
91
|
+
isLibrary: false,
|
|
92
|
+
shouldOptimize: false,
|
|
93
|
+
shouldScopeHoist: false,
|
|
94
|
+
sourceMap: undefined,
|
|
95
|
+
loc: undefined,
|
|
96
|
+
sourceType: 'module',
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// @flow strict-local
|
|
2
|
+
|
|
3
|
+
import assert from 'assert';
|
|
4
|
+
import UncommittedAsset from '../src/UncommittedAsset';
|
|
5
|
+
import {createAsset as _createAsset} from '../src/assetUtils';
|
|
6
|
+
import {createEnvironment} from '../src/Environment';
|
|
7
|
+
import {DEFAULT_OPTIONS} from './test-utils';
|
|
8
|
+
import {toProjectPath} from '../src/projectPath';
|
|
9
|
+
|
|
10
|
+
function createAsset(opts) {
|
|
11
|
+
return _createAsset('/', opts);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const stats = {time: 0, size: 0};
|
|
15
|
+
|
|
16
|
+
describe('InternalAsset', () => {
|
|
17
|
+
it('only includes connected files once per filePath', () => {
|
|
18
|
+
let asset = new UncommittedAsset({
|
|
19
|
+
value: createAsset({
|
|
20
|
+
filePath: toProjectPath('/', '/foo/asset.js'),
|
|
21
|
+
env: createEnvironment(),
|
|
22
|
+
stats,
|
|
23
|
+
type: 'js',
|
|
24
|
+
isSource: true,
|
|
25
|
+
}),
|
|
26
|
+
options: DEFAULT_OPTIONS,
|
|
27
|
+
});
|
|
28
|
+
asset.invalidateOnFileChange(toProjectPath('/', '/foo/file'));
|
|
29
|
+
asset.invalidateOnFileChange(toProjectPath('/', '/foo/file'));
|
|
30
|
+
assert.deepEqual(
|
|
31
|
+
asset.invalidations.invalidateOnFileChange,
|
|
32
|
+
new Set(['foo/file']),
|
|
33
|
+
);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('only includes dependencies once per id', () => {
|
|
37
|
+
let asset = new UncommittedAsset({
|
|
38
|
+
value: createAsset({
|
|
39
|
+
filePath: toProjectPath('/', '/foo/asset.js'),
|
|
40
|
+
env: createEnvironment(),
|
|
41
|
+
stats,
|
|
42
|
+
type: 'js',
|
|
43
|
+
isSource: true,
|
|
44
|
+
}),
|
|
45
|
+
options: DEFAULT_OPTIONS,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
asset.addDependency({specifier: './foo', specifierType: 'esm'});
|
|
49
|
+
asset.addDependency({specifier: './foo', specifierType: 'esm'});
|
|
50
|
+
let dependencies = asset.getDependencies();
|
|
51
|
+
assert(dependencies.length === 1);
|
|
52
|
+
assert(dependencies[0].specifier === './foo');
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('includes different dependencies if their id differs', () => {
|
|
56
|
+
let asset = new UncommittedAsset({
|
|
57
|
+
value: createAsset({
|
|
58
|
+
filePath: toProjectPath('/', '/foo/asset.js'),
|
|
59
|
+
env: createEnvironment(),
|
|
60
|
+
stats,
|
|
61
|
+
type: 'js',
|
|
62
|
+
isSource: true,
|
|
63
|
+
}),
|
|
64
|
+
options: DEFAULT_OPTIONS,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
asset.addDependency({specifier: './foo', specifierType: 'esm'});
|
|
68
|
+
asset.addDependency({
|
|
69
|
+
specifier: './foo',
|
|
70
|
+
specifierType: 'esm',
|
|
71
|
+
env: {context: 'web-worker', engines: {}},
|
|
72
|
+
});
|
|
73
|
+
let dependencies = asset.getDependencies();
|
|
74
|
+
assert(dependencies.length === 2);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// // @flow
|
|
2
|
+
// 'use strict';
|
|
3
|
+
|
|
4
|
+
// const PackagerRunner = require('../src/PackagerRunner');
|
|
5
|
+
// const assert = require('assert');
|
|
6
|
+
// const path = require('path');
|
|
7
|
+
|
|
8
|
+
// const config = require('@atlaspack/config-default');
|
|
9
|
+
|
|
10
|
+
// describe('PackagerRunner', () => {
|
|
11
|
+
// it('works', async () => {
|
|
12
|
+
// let bundle = {
|
|
13
|
+
// destPath: path.join(__dirname, 'dist', 'bundle.js'),
|
|
14
|
+
// assets: [
|
|
15
|
+
// {blobs: {code: require.resolve('./fixtures/module-a')}},
|
|
16
|
+
// {blobs: {code: require.resolve('./fixtures/module-b')}},
|
|
17
|
+
// ],
|
|
18
|
+
// };
|
|
19
|
+
|
|
20
|
+
// let packagerRunner = new PackagerRunner({
|
|
21
|
+
// atlaspackConfig: config,
|
|
22
|
+
// options: {}
|
|
23
|
+
// });
|
|
24
|
+
|
|
25
|
+
// await packagerRunner.runPackager({ bundle });
|
|
26
|
+
// });
|
|
27
|
+
// });
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// @flow strict-local
|
|
2
|
+
|
|
3
|
+
import assert from 'assert';
|
|
4
|
+
import {Asset, MutableAsset} from '../src/public/Asset';
|
|
5
|
+
import UncommittedAsset from '../src/UncommittedAsset';
|
|
6
|
+
import {createAsset as _createAsset} from '../src/assetUtils';
|
|
7
|
+
import {createEnvironment} from '../src/Environment';
|
|
8
|
+
import {DEFAULT_OPTIONS} from './test-utils';
|
|
9
|
+
import {toProjectPath} from '../src/projectPath';
|
|
10
|
+
|
|
11
|
+
function createAsset(opts) {
|
|
12
|
+
return _createAsset('/', opts);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
describe('Public Asset', () => {
|
|
16
|
+
let internalAsset;
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
internalAsset = new UncommittedAsset({
|
|
19
|
+
options: DEFAULT_OPTIONS,
|
|
20
|
+
value: createAsset({
|
|
21
|
+
filePath: toProjectPath('/', '/does/not/exist'),
|
|
22
|
+
type: 'js',
|
|
23
|
+
env: createEnvironment({}),
|
|
24
|
+
isSource: true,
|
|
25
|
+
stats: {size: 0, time: 0},
|
|
26
|
+
}),
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('returns the same public Asset given an internal asset', () => {
|
|
31
|
+
assert.equal(new Asset(internalAsset), new Asset(internalAsset));
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('returns the same public MutableAsset given an internal asset', () => {
|
|
35
|
+
assert.equal(
|
|
36
|
+
new MutableAsset(internalAsset),
|
|
37
|
+
new MutableAsset(internalAsset),
|
|
38
|
+
);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// @flow strict-local
|
|
2
|
+
import type {Bundle as InternalBundle} from '../src/types';
|
|
3
|
+
|
|
4
|
+
import assert from 'assert';
|
|
5
|
+
import {ContentGraph} from '@atlaspack/graph';
|
|
6
|
+
|
|
7
|
+
import {Bundle, NamedBundle, PackagedBundle} from '../src/public/Bundle';
|
|
8
|
+
import BundleGraph from '../src/BundleGraph';
|
|
9
|
+
import {createEnvironment} from '../src/Environment';
|
|
10
|
+
import {DEFAULT_OPTIONS} from './test-utils';
|
|
11
|
+
import {toProjectPath} from '../src/projectPath';
|
|
12
|
+
|
|
13
|
+
describe('Public Bundle', () => {
|
|
14
|
+
let internalBundle: InternalBundle;
|
|
15
|
+
let bundleGraph;
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
let env = createEnvironment({});
|
|
18
|
+
internalBundle = {
|
|
19
|
+
id: '123',
|
|
20
|
+
hashReference: '@@HASH_REFERENCE_123',
|
|
21
|
+
entryAssetIds: [],
|
|
22
|
+
mainEntryId: null,
|
|
23
|
+
type: 'js',
|
|
24
|
+
env,
|
|
25
|
+
name: null,
|
|
26
|
+
displayName: null,
|
|
27
|
+
publicId: null,
|
|
28
|
+
pipeline: null,
|
|
29
|
+
needsStableName: null,
|
|
30
|
+
bundleBehavior: null,
|
|
31
|
+
isSplittable: true,
|
|
32
|
+
target: {
|
|
33
|
+
env,
|
|
34
|
+
distDir: toProjectPath('/', '/'),
|
|
35
|
+
name: '',
|
|
36
|
+
publicUrl: '',
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
bundleGraph = new BundleGraph({
|
|
41
|
+
graph: new ContentGraph(),
|
|
42
|
+
assetPublicIds: new Set(),
|
|
43
|
+
publicIdByAssetId: new Map(),
|
|
44
|
+
bundleContentHashes: new Map(),
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('returns the same public Bundle given an internal bundle', () => {
|
|
49
|
+
assert.equal(
|
|
50
|
+
Bundle.get(internalBundle, bundleGraph, DEFAULT_OPTIONS),
|
|
51
|
+
Bundle.get(internalBundle, bundleGraph, DEFAULT_OPTIONS),
|
|
52
|
+
);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('returns the same public NamedBundle given an internal bundle', () => {
|
|
56
|
+
assert.equal(
|
|
57
|
+
NamedBundle.get(internalBundle, bundleGraph, DEFAULT_OPTIONS),
|
|
58
|
+
NamedBundle.get(internalBundle, bundleGraph, DEFAULT_OPTIONS),
|
|
59
|
+
);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('returns the same public PackagedBundle given an internal bundle', () => {
|
|
63
|
+
assert.equal(
|
|
64
|
+
PackagedBundle.get(internalBundle, bundleGraph, DEFAULT_OPTIONS),
|
|
65
|
+
PackagedBundle.get(internalBundle, bundleGraph, DEFAULT_OPTIONS),
|
|
66
|
+
);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// @flow strict-local
|
|
2
|
+
|
|
3
|
+
import assert from 'assert';
|
|
4
|
+
import {createEnvironment} from '../src/Environment';
|
|
5
|
+
import {createDependency} from '../src/Dependency';
|
|
6
|
+
import {getPublicDependency} from '../src/public/Dependency';
|
|
7
|
+
import {DEFAULT_OPTIONS} from './test-utils';
|
|
8
|
+
|
|
9
|
+
describe('Public Dependency', () => {
|
|
10
|
+
it('returns the same public Dependency given an internal dependency', () => {
|
|
11
|
+
let internalDependency = createDependency('/', {
|
|
12
|
+
specifier: 'foo',
|
|
13
|
+
specifierType: 'esm',
|
|
14
|
+
env: createEnvironment({}),
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
assert.equal(
|
|
18
|
+
getPublicDependency(internalDependency, DEFAULT_OPTIONS),
|
|
19
|
+
getPublicDependency(internalDependency, DEFAULT_OPTIONS),
|
|
20
|
+
);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// @flow strict-local
|
|
2
|
+
|
|
3
|
+
import assert from 'assert';
|
|
4
|
+
import {createEnvironment} from '../src/Environment';
|
|
5
|
+
import PublicEnvironment from '../src/public/Environment';
|
|
6
|
+
import {DEFAULT_OPTIONS} from './test-utils';
|
|
7
|
+
|
|
8
|
+
describe('Public Environment', () => {
|
|
9
|
+
it('has correct support data for ChromeAndroid', () => {
|
|
10
|
+
let env = new PublicEnvironment(
|
|
11
|
+
createEnvironment({
|
|
12
|
+
context: 'browser',
|
|
13
|
+
engines: {
|
|
14
|
+
browsers: ['last 1 Chrome version', 'last 1 ChromeAndroid version'],
|
|
15
|
+
},
|
|
16
|
+
outputFormat: 'esmodule',
|
|
17
|
+
}),
|
|
18
|
+
DEFAULT_OPTIONS,
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
assert(env.supports('esmodules'));
|
|
22
|
+
assert(env.supports('dynamic-import'));
|
|
23
|
+
assert(env.supports('worker-module'));
|
|
24
|
+
assert(env.supports('import-meta-url'));
|
|
25
|
+
assert(env.supports('arrow-functions'));
|
|
26
|
+
});
|
|
27
|
+
});
|