@oicl/openbridge-webcomponents-full-bundle 2.1.0-next.5 → 2.1.0-next.6
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/package.json
CHANGED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// Collapses the Angular package's per-entry-point `exports` into one subpath
|
|
2
|
+
// pattern. ng-packagr writes an explicit export for every secondary entry
|
|
3
|
+
// point (one per component and icon, ~2400), which makes dist/package.json
|
|
4
|
+
// ~445 kB. Some npm-compatible registries cap package.json at 384000 bytes
|
|
5
|
+
// and reject the publish. Every generated entry follows the same layout, so
|
|
6
|
+
// a single `./*` pattern resolves to exactly the same files.
|
|
7
|
+
//
|
|
8
|
+
// Usage: node compact-ng-exports.mjs <path/to/dist/package.json>
|
|
9
|
+
import * as fs from 'node:fs';
|
|
10
|
+
import * as path from 'node:path';
|
|
11
|
+
import {fileURLToPath} from 'node:url';
|
|
12
|
+
|
|
13
|
+
const PATTERN_KEY = './*';
|
|
14
|
+
/** The smallest registry `package.json` cap seen in the field. */
|
|
15
|
+
const MAX_PACKAGE_JSON_BYTES = 384000;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Returns a copy of `packageJson` whose secondary entry-point exports are
|
|
19
|
+
* replaced by one `./*` pattern. Entries that do not match the pattern exactly
|
|
20
|
+
* (nested subpaths, extra conditions) are kept as explicit exports, which take
|
|
21
|
+
* precedence over the pattern.
|
|
22
|
+
*/
|
|
23
|
+
export function compactNgExports(packageJson) {
|
|
24
|
+
const exportsMap = packageJson.exports;
|
|
25
|
+
const mainBundle = exportsMap?.['.']?.default;
|
|
26
|
+
if (!mainBundle || !/^\.\/fesm2022\/[^/]+\.mjs$/.test(mainBundle)) {
|
|
27
|
+
throw new Error(
|
|
28
|
+
`Unexpected main export ${JSON.stringify(mainBundle)}; refusing to compact exports.`
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
if (exportsMap[PATTERN_KEY]) {
|
|
32
|
+
return {packageJson, collapsed: 0};
|
|
33
|
+
}
|
|
34
|
+
const bundlePrefix = mainBundle.replace(/\.mjs$/, '-');
|
|
35
|
+
const pattern = {
|
|
36
|
+
types: './*/index.d.ts',
|
|
37
|
+
default: `${bundlePrefix}*.mjs`,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const kept = {};
|
|
41
|
+
let collapsed = 0;
|
|
42
|
+
for (const [key, value] of Object.entries(exportsMap)) {
|
|
43
|
+
const name = key.slice(2);
|
|
44
|
+
const matchesPattern =
|
|
45
|
+
key.startsWith('./') &&
|
|
46
|
+
name !== '' &&
|
|
47
|
+
!name.includes('/') &&
|
|
48
|
+
!name.includes('*') &&
|
|
49
|
+
value !== null &&
|
|
50
|
+
typeof value === 'object' &&
|
|
51
|
+
Object.keys(value).join() === 'types,default' &&
|
|
52
|
+
value.types === pattern.types.replace('*', name) &&
|
|
53
|
+
value.default === pattern.default.replace('*', name);
|
|
54
|
+
if (matchesPattern) {
|
|
55
|
+
collapsed++;
|
|
56
|
+
} else {
|
|
57
|
+
kept[key] = value;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (collapsed === 0) {
|
|
61
|
+
return {packageJson, collapsed};
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
packageJson: {...packageJson, exports: {...kept, [PATTERN_KEY]: pattern}},
|
|
65
|
+
collapsed,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function main() {
|
|
70
|
+
const packageJsonPath = process.argv[2];
|
|
71
|
+
if (!packageJsonPath) {
|
|
72
|
+
throw new Error('Usage: compact-ng-exports.mjs <dist/package.json>');
|
|
73
|
+
}
|
|
74
|
+
const before = fs.readFileSync(packageJsonPath, 'utf-8');
|
|
75
|
+
const {packageJson, collapsed} = compactNgExports(JSON.parse(before));
|
|
76
|
+
|
|
77
|
+
// Every collapsed entry must still resolve to files that exist.
|
|
78
|
+
const root = path.dirname(packageJsonPath);
|
|
79
|
+
const pattern = packageJson.exports[PATTERN_KEY];
|
|
80
|
+
const names = fs
|
|
81
|
+
.readdirSync(root, {withFileTypes: true})
|
|
82
|
+
.filter((entry) => fs.existsSync(path.join(root, entry.name, 'index.d.ts')))
|
|
83
|
+
.map((entry) => entry.name);
|
|
84
|
+
for (const name of names) {
|
|
85
|
+
if (packageJson.exports[`./${name}`]) continue;
|
|
86
|
+
for (const target of [pattern.types, pattern.default]) {
|
|
87
|
+
const file = path.join(root, target.replaceAll('*', name));
|
|
88
|
+
if (!fs.existsSync(file)) {
|
|
89
|
+
throw new Error(`Pattern export for ./${name} misses ${file}`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const after = JSON.stringify(packageJson, null, 2) + '\n';
|
|
95
|
+
fs.writeFileSync(packageJsonPath, after);
|
|
96
|
+
console.log(
|
|
97
|
+
`compact-ng-exports: collapsed ${collapsed} exports into "${PATTERN_KEY}", ` +
|
|
98
|
+
`package.json ${Buffer.byteLength(before)} -> ${Buffer.byteLength(after)} bytes`
|
|
99
|
+
);
|
|
100
|
+
if (Buffer.byteLength(after) > MAX_PACKAGE_JSON_BYTES) {
|
|
101
|
+
throw new Error(
|
|
102
|
+
`${packageJsonPath} is still over ${MAX_PACKAGE_JSON_BYTES} bytes; registries will reject the publish.`
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (process.argv[1] === fileURLToPath(import.meta.url)) {
|
|
108
|
+
main();
|
|
109
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import {describe, expect, it} from 'vitest';
|
|
2
|
+
import {compactNgExports} from './compact-ng-exports.mjs';
|
|
3
|
+
|
|
4
|
+
const bundle = './fesm2022/oicl-openbridge-webcomponents-ng';
|
|
5
|
+
|
|
6
|
+
function entry(name: string) {
|
|
7
|
+
return {types: `./${name}/index.d.ts`, default: `${bundle}-${name}.mjs`};
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const packageJson = {
|
|
11
|
+
name: '@oicl/openbridge-webcomponents-ng',
|
|
12
|
+
exports: {
|
|
13
|
+
'./package.json': {default: './package.json'},
|
|
14
|
+
'.': {types: './index.d.ts', default: `${bundle}.mjs`},
|
|
15
|
+
'./obc-button': entry('obc-button'),
|
|
16
|
+
'./obi-02-illustration': entry('obi-02-illustration'),
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
describe('compactNgExports', () => {
|
|
21
|
+
it('replaces matching entry points with one pattern', () => {
|
|
22
|
+
const {packageJson: result, collapsed} = compactNgExports(packageJson);
|
|
23
|
+
expect(collapsed).toBe(2);
|
|
24
|
+
expect(result.exports).toEqual({
|
|
25
|
+
'./package.json': {default: './package.json'},
|
|
26
|
+
'.': {types: './index.d.ts', default: `${bundle}.mjs`},
|
|
27
|
+
'./*': {types: './*/index.d.ts', default: `${bundle}-*.mjs`},
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('keeps entries the pattern would resolve differently', () => {
|
|
32
|
+
const odd = {
|
|
33
|
+
...packageJson,
|
|
34
|
+
exports: {
|
|
35
|
+
...packageJson.exports,
|
|
36
|
+
'./nested/entry': entry('nested/entry'),
|
|
37
|
+
'./with-style': {...entry('with-style'), style: './style.css'},
|
|
38
|
+
'./renamed': {
|
|
39
|
+
types: './renamed/index.d.ts',
|
|
40
|
+
default: `${bundle}-other.mjs`,
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
const {packageJson: result, collapsed} = compactNgExports(odd);
|
|
45
|
+
expect(collapsed).toBe(2);
|
|
46
|
+
expect(Object.keys(result.exports)).toEqual([
|
|
47
|
+
'./package.json',
|
|
48
|
+
'.',
|
|
49
|
+
'./nested/entry',
|
|
50
|
+
'./with-style',
|
|
51
|
+
'./renamed',
|
|
52
|
+
'./*',
|
|
53
|
+
]);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('is a no-op on an already compacted manifest', () => {
|
|
57
|
+
const once = compactNgExports(packageJson).packageJson;
|
|
58
|
+
const twice = compactNgExports(once);
|
|
59
|
+
expect(twice.collapsed).toBe(0);
|
|
60
|
+
expect(twice.packageJson).toBe(once);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('refuses a manifest without the expected main bundle', () => {
|
|
64
|
+
expect(() => compactNgExports({exports: {}})).toThrow(/main export/);
|
|
65
|
+
});
|
|
66
|
+
});
|