@atlaspack/reporter-conditional-manifest 2.12.1-dev.3502 → 2.12.1-dev.3565
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/lib/ConditionalManifestReporter.js +34 -37
- package/lib/Config.js +33 -0
- package/package.json +5 -5
- package/src/ConditionalManifestReporter.js +57 -40
- package/src/Config.js +31 -0
- package/test/Config.test.js +67 -0
|
@@ -18,45 +18,39 @@ function _plugin() {
|
|
|
18
18
|
};
|
|
19
19
|
return data;
|
|
20
20
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
var _default = exports.default = new (_plugin().Reporter)({
|
|
30
|
-
async report({
|
|
31
|
-
event,
|
|
32
|
-
options,
|
|
33
|
-
logger
|
|
34
|
-
}) {
|
|
35
|
-
if (event.type === 'buildSuccess') {
|
|
36
|
-
const bundles = event.bundleGraph.getConditionalBundleMapping();
|
|
21
|
+
var _Config = require("./Config");
|
|
22
|
+
async function report({
|
|
23
|
+
event,
|
|
24
|
+
options,
|
|
25
|
+
logger
|
|
26
|
+
}) {
|
|
27
|
+
if (event.type === 'buildSuccess') {
|
|
28
|
+
const bundles = event.bundleGraph.getConditionalBundleMapping();
|
|
37
29
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
manifest[(0, _path().relative)(bundle.target.distDir, bundle.filePath)] = bundleInfo;
|
|
30
|
+
// Replace bundles with file paths
|
|
31
|
+
const mapBundles = bundles => bundles.map(bundle => (0, _path().relative)(bundle.target.distDir, bundle.filePath));
|
|
32
|
+
const manifest = {};
|
|
33
|
+
for (const [bundle, conditions] of bundles.entries()) {
|
|
34
|
+
const bundleInfo = {};
|
|
35
|
+
for (const [key, cond] of conditions) {
|
|
36
|
+
bundleInfo[key] = {
|
|
37
|
+
// Reverse bundles so we load children bundles first
|
|
38
|
+
ifTrueBundles: mapBundles(cond.ifTrueBundles).reverse(),
|
|
39
|
+
ifFalseBundles: mapBundles(cond.ifFalseBundles).reverse()
|
|
40
|
+
};
|
|
50
41
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const conditionalManifestFilename = (0, _path().join)(
|
|
42
|
+
manifest[bundle.target.name] ??= {};
|
|
43
|
+
manifest[bundle.target.name][(0, _path().relative)(bundle.target.distDir, bundle.filePath)] = bundleInfo;
|
|
44
|
+
}
|
|
45
|
+
const targets = new Set(event.bundleGraph.getBundles().map(bundle => bundle.target));
|
|
46
|
+
const {
|
|
47
|
+
filename
|
|
48
|
+
} = await (0, _Config.getConfig)(options);
|
|
49
|
+
for (const target of targets) {
|
|
50
|
+
const conditionalManifestFilename = (0, _path().join)(target.distDir, filename);
|
|
51
|
+
const conditionalManifest = JSON.stringify(
|
|
52
|
+
// If there's no content, send an empty manifest so we can still map from it safely
|
|
53
|
+
manifest[target.name] ?? {}, null, 2);
|
|
60
54
|
await options.outputFS.writeFile(conditionalManifestFilename, conditionalManifest, {
|
|
61
55
|
mode: 0o666
|
|
62
56
|
});
|
|
@@ -65,4 +59,7 @@ var _default = exports.default = new (_plugin().Reporter)({
|
|
|
65
59
|
});
|
|
66
60
|
}
|
|
67
61
|
}
|
|
62
|
+
}
|
|
63
|
+
var _default = exports.default = new (_plugin().Reporter)({
|
|
64
|
+
report
|
|
68
65
|
});
|
package/lib/Config.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getConfig = getConfig;
|
|
7
|
+
function _path() {
|
|
8
|
+
const data = require("path");
|
|
9
|
+
_path = function () {
|
|
10
|
+
return data;
|
|
11
|
+
};
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
14
|
+
async function getConfig({
|
|
15
|
+
env,
|
|
16
|
+
inputFS,
|
|
17
|
+
projectRoot
|
|
18
|
+
}) {
|
|
19
|
+
const packageJson = JSON.parse(await inputFS.readFile((0, _path().join)(projectRoot, 'package.json'), 'utf8'));
|
|
20
|
+
const config = packageJson['@atlaspack/reporter-conditional-manifest'] ?? {};
|
|
21
|
+
for (const [key, value] of Object.entries(config)) {
|
|
22
|
+
// Replace values in the format of ${VARIABLE} with their corresponding env
|
|
23
|
+
if (typeof value === 'string') {
|
|
24
|
+
config[key] = value.replace(/\${([^}]+)}/g, (_, v) => env[v] ?? '');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const {
|
|
28
|
+
filename
|
|
29
|
+
} = config;
|
|
30
|
+
return {
|
|
31
|
+
filename: filename ?? 'conditional-manifest.json'
|
|
32
|
+
};
|
|
33
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/reporter-conditional-manifest",
|
|
3
|
-
"version": "2.12.1-dev.
|
|
3
|
+
"version": "2.12.1-dev.3565+b31bc6b33",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -12,12 +12,12 @@
|
|
|
12
12
|
"main": "lib/ConditionalManifestReporter.js",
|
|
13
13
|
"source": "src/ConditionalManifestReporter.js",
|
|
14
14
|
"engines": {
|
|
15
|
-
"
|
|
16
|
-
"
|
|
15
|
+
"atlaspack": "^2.12.1-dev.3565+b31bc6b33",
|
|
16
|
+
"node": ">= 16.0.0"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@atlaspack/plugin": "2.12.1-dev.
|
|
19
|
+
"@atlaspack/plugin": "2.12.1-dev.3565+b31bc6b33",
|
|
20
20
|
"nullthrows": "^1.1.1"
|
|
21
21
|
},
|
|
22
|
-
"gitHead": "
|
|
22
|
+
"gitHead": "b31bc6b33de40c158b9f4d8ff177238be0de409d"
|
|
23
23
|
}
|
|
@@ -1,49 +1,64 @@
|
|
|
1
1
|
// @flow strict-local
|
|
2
2
|
import {relative, join} from 'path';
|
|
3
3
|
import {Reporter} from '@atlaspack/plugin';
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const mapBundles = (bundles) =>
|
|
13
|
-
bundles.map((bundle) =>
|
|
14
|
-
relative(bundle.target.distDir, bundle.filePath),
|
|
15
|
-
);
|
|
16
|
-
|
|
17
|
-
const manifest = {};
|
|
18
|
-
for (const [bundle, conditions] of bundles.entries()) {
|
|
19
|
-
const bundleInfo = {};
|
|
20
|
-
for (const [key, cond] of conditions) {
|
|
21
|
-
bundleInfo[key] = {
|
|
22
|
-
ifTrueBundles: mapBundles(cond.ifTrueBundles).reverse(),
|
|
23
|
-
ifFalseBundles: mapBundles(cond.ifFalseBundles).reverse(),
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
manifest[relative(bundle.target.distDir, bundle.filePath)] = bundleInfo;
|
|
28
|
-
}
|
|
4
|
+
import type {
|
|
5
|
+
Async,
|
|
6
|
+
PluginLogger,
|
|
7
|
+
PluginOptions,
|
|
8
|
+
PluginTracer,
|
|
9
|
+
ReporterEvent,
|
|
10
|
+
} from '@atlaspack/types-internal';
|
|
11
|
+
import {getConfig} from './Config';
|
|
29
12
|
|
|
30
|
-
|
|
13
|
+
async function report({
|
|
14
|
+
event,
|
|
15
|
+
options,
|
|
16
|
+
logger,
|
|
17
|
+
}: {|
|
|
18
|
+
event: ReporterEvent,
|
|
19
|
+
options: PluginOptions,
|
|
20
|
+
logger: PluginLogger,
|
|
21
|
+
tracer: PluginTracer,
|
|
22
|
+
|}): Async<void> {
|
|
23
|
+
if (event.type === 'buildSuccess') {
|
|
24
|
+
const bundles = event.bundleGraph.getConditionalBundleMapping();
|
|
31
25
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
26
|
+
// Replace bundles with file paths
|
|
27
|
+
const mapBundles = (bundles) =>
|
|
28
|
+
bundles.map((bundle) => relative(bundle.target.distDir, bundle.filePath));
|
|
29
|
+
|
|
30
|
+
const manifest = {};
|
|
31
|
+
for (const [bundle, conditions] of bundles.entries()) {
|
|
32
|
+
const bundleInfo = {};
|
|
33
|
+
for (const [key, cond] of conditions) {
|
|
34
|
+
bundleInfo[key] = {
|
|
35
|
+
// Reverse bundles so we load children bundles first
|
|
36
|
+
ifTrueBundles: mapBundles(cond.ifTrueBundles).reverse(),
|
|
37
|
+
ifFalseBundles: mapBundles(cond.ifFalseBundles).reverse(),
|
|
38
|
+
};
|
|
40
39
|
}
|
|
41
40
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
manifest[bundle.target.name] ??= {};
|
|
42
|
+
manifest[bundle.target.name][
|
|
43
|
+
relative(bundle.target.distDir, bundle.filePath)
|
|
44
|
+
] = bundleInfo;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const targets = new Set(
|
|
48
|
+
event.bundleGraph.getBundles().map((bundle) => bundle.target),
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
const {filename} = await getConfig(options);
|
|
52
|
+
|
|
53
|
+
for (const target of targets) {
|
|
54
|
+
const conditionalManifestFilename = join(target.distDir, filename);
|
|
55
|
+
const conditionalManifest = JSON.stringify(
|
|
56
|
+
// If there's no content, send an empty manifest so we can still map from it safely
|
|
57
|
+
manifest[target.name] ?? {},
|
|
58
|
+
null,
|
|
59
|
+
2,
|
|
46
60
|
);
|
|
61
|
+
|
|
47
62
|
await options.outputFS.writeFile(
|
|
48
63
|
conditionalManifestFilename,
|
|
49
64
|
conditionalManifest,
|
|
@@ -54,5 +69,7 @@ export default (new Reporter({
|
|
|
54
69
|
message: 'Wrote conditional manifest to ' + conditionalManifestFilename,
|
|
55
70
|
});
|
|
56
71
|
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export default (new Reporter({report}): Reporter);
|
package/src/Config.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// @flow strict-local
|
|
2
|
+
import {join} from 'path';
|
|
3
|
+
import type {PluginOptions} from '@atlaspack/types-internal';
|
|
4
|
+
|
|
5
|
+
type Config = {|
|
|
6
|
+
filename: string,
|
|
7
|
+
|};
|
|
8
|
+
|
|
9
|
+
export async function getConfig({
|
|
10
|
+
env,
|
|
11
|
+
inputFS,
|
|
12
|
+
projectRoot,
|
|
13
|
+
}: PluginOptions): Promise<Config> {
|
|
14
|
+
const packageJson = JSON.parse(
|
|
15
|
+
await inputFS.readFile(join(projectRoot, 'package.json'), 'utf8'),
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
const config = packageJson['@atlaspack/reporter-conditional-manifest'] ?? {};
|
|
19
|
+
for (const [key, value] of Object.entries(config)) {
|
|
20
|
+
// Replace values in the format of ${VARIABLE} with their corresponding env
|
|
21
|
+
if (typeof value === 'string') {
|
|
22
|
+
config[key] = value.replace(/\${([^}]+)}/g, (_, v) => env[v] ?? '');
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const {filename} = config;
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
filename: filename ?? 'conditional-manifest.json',
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// @flow strict-local
|
|
2
|
+
import type {PluginOptions, EnvMap} from '@atlaspack/types-internal';
|
|
3
|
+
|
|
4
|
+
import {NodePackageManager} from '@atlaspack/package-manager';
|
|
5
|
+
import {getConfig} from '../src/Config';
|
|
6
|
+
import {overlayFS, fsFixture} from '@atlaspack/test-utils';
|
|
7
|
+
import assert from 'assert';
|
|
8
|
+
import {DEFAULT_FEATURE_FLAGS} from '@atlaspack/feature-flags';
|
|
9
|
+
|
|
10
|
+
function getPluginOptions({env}: {env?: EnvMap, ...}): PluginOptions {
|
|
11
|
+
return {
|
|
12
|
+
mode: 'development',
|
|
13
|
+
parcelVersion: 'version',
|
|
14
|
+
serveOptions: false,
|
|
15
|
+
shouldBuildLazily: false,
|
|
16
|
+
shouldAutoInstall: false,
|
|
17
|
+
logLevel: 'info',
|
|
18
|
+
cacheDir: '.parcel-cache/',
|
|
19
|
+
packageManager: new NodePackageManager(overlayFS, '/'),
|
|
20
|
+
instanceId: 'instance-id',
|
|
21
|
+
featureFlags: DEFAULT_FEATURE_FLAGS,
|
|
22
|
+
detailedReport: undefined,
|
|
23
|
+
hmrOptions: undefined,
|
|
24
|
+
inputFS: overlayFS,
|
|
25
|
+
outputFS: overlayFS,
|
|
26
|
+
projectRoot: '/project-root',
|
|
27
|
+
env: env ?? {},
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
describe('ConditionalManifestReporter', function () {
|
|
32
|
+
it('should load filename from config', async function () {
|
|
33
|
+
const pluginOptions = getPluginOptions({});
|
|
34
|
+
overlayFS.mkdirp(pluginOptions.projectRoot);
|
|
35
|
+
|
|
36
|
+
await fsFixture(overlayFS, pluginOptions.projectRoot)`
|
|
37
|
+
package.json:
|
|
38
|
+
{
|
|
39
|
+
"@atlaspack/reporter-conditional-manifest": {
|
|
40
|
+
"filename": "../some-other-dir/conditional.json"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
`;
|
|
44
|
+
|
|
45
|
+
const {filename} = await getConfig(pluginOptions);
|
|
46
|
+
|
|
47
|
+
assert.equal(filename, '../some-other-dir/conditional.json');
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('should load filename from config with env vars', async function () {
|
|
51
|
+
const pluginOptions = getPluginOptions({env: {USER: 'some-user'}});
|
|
52
|
+
overlayFS.mkdirp(pluginOptions.projectRoot);
|
|
53
|
+
|
|
54
|
+
await fsFixture(overlayFS, pluginOptions.projectRoot)`
|
|
55
|
+
package.json:
|
|
56
|
+
{
|
|
57
|
+
"@atlaspack/reporter-conditional-manifest": {
|
|
58
|
+
"filename": "../\${USER}/conditional.json"
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
`;
|
|
62
|
+
|
|
63
|
+
const {filename} = await getConfig(pluginOptions);
|
|
64
|
+
|
|
65
|
+
assert.equal(filename, '../some-user/conditional.json');
|
|
66
|
+
});
|
|
67
|
+
});
|