Skip to content

Commit f691451

Browse files
authored
better polyfills elimination from dlls
1 parent c5def4d commit f691451

File tree

13 files changed

+81
-136
lines changed

13 files changed

+81
-136
lines changed

bootstrap/scripts/link.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ async function linkSelfAsModule() {
5555

5656
await linkDependenciesModules();
5757
await linkDevModule("core-js");
58+
await linkDevModule("tslib");
5859
await linkDLL("dependencies");
5960
await linkDLL("rocker", "platform");
6061
await linkSelfAsModule();

bootstrap/scripts/unlink.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ async function unlinkModule(...nodePath) {
2121

2222
await unlinkModule("@lastui", "rocker", "bootstrap");
2323
await unlinkModule("core-js");
24+
await unlinkModule("tslib");
2425
await unlinkDLL("dependencies");
2526
await unlinkDLL("rocker", "platform");
2627
await ulinkDependenciesModules();

dependencies/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@lastui/dependencies",
3-
"version": "1.5.2",
3+
"version": "1.5.3",
44
"license": "Apache-2.0",
55
"author": "[email protected]",
66
"homepage": "https://github.com/lastui/rocker#readme",
@@ -19,7 +19,7 @@
1919
"scripts": {
2020
"prebuild": "npm ci --no-fund --no-audit && node ./scripts/link.mjs",
2121
"build": "npm run build:dev && npm run build:prod",
22-
"postbuild": "node ./scripts/unlink.mjs && node ../cli/index.js lint --fix",
22+
"postbuild": "node ./scripts/unlink.mjs",
2323
"build:dev": "NODE_ENV=development node ./scripts/build.mjs",
2424
"build:prod": "NODE_ENV=production node ./scripts/build.mjs"
2525
},

dependencies/scripts/link.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ async function linkDevModule(...nodePath) {
1616
}
1717

1818
await linkDevModule("core-js");
19+
await linkDevModule("tslib");
1920
await linkDevModule("buffer");
2021
await linkDevModule("ieee754");

dependencies/scripts/unlink.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ async function unlinkModule(...nodePath) {
1010
}
1111

1212
await unlinkModule("core-js");
13+
await unlinkModule("tslib");
1314
await unlinkModule("buffer");
1415
await unlinkModule("ieee754");

dependencies/scripts/verify-dlls.mjs

+32-29
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,12 @@ import path from "node:path";
44
import { Readable } from "node:stream";
55
import glob from "glob";
66

7-
async function cleanupManifest(filename) {
8-
let changed = false;
9-
10-
const manifestFile = path.resolve(fileURLToPath(import.meta.url), "..", "..", "dll", filename);
11-
const manifest = JSON.parse(await fs.readFile(manifestFile, { encoding: "utf8" }));
12-
13-
const polyfills = [
14-
"./node_modules/regenerator-runtime/",
15-
"./node_modules/@babel/runtime",
16-
"./node_modules/core-js",
17-
"tslib/tslib.es6.js",
18-
];
19-
20-
for (const key in manifest.content) {
21-
if (polyfills.includes(key)) {
22-
changed = true;
23-
delete manifest.content[key];
24-
}
25-
}
26-
if (changed) {
27-
await fs.writeFile(manifestFile, JSON.stringify(manifest, null, 2));
28-
}
29-
}
30-
31-
async function checkManifests(pattern) {
7+
async function verifyManifests(pattern) {
328
const fileStream = new Readable({ objectMode: true });
339
fileStream._read = () => {};
3410

3511
glob(
36-
pattern,
12+
pattern + "*-manifest.json",
3713
{
3814
cwd: path.resolve(fileURLToPath(import.meta.url), "..", "..", "dll"),
3915
ignore: [],
@@ -50,6 +26,13 @@ async function checkManifests(pattern) {
5026
},
5127
);
5228

29+
const polyfills = [
30+
"./node_modules/regenerator-runtime/",
31+
"./node_modules/@babel/runtime",
32+
"./node_modules/core-js",
33+
"./node_modules/tslib",
34+
];
35+
5336
for await (const filePath of fileStream) {
5437
const manifestFile = path.resolve(fileURLToPath(import.meta.url), "..", "..", "dll", filePath);
5538
const manifest = JSON.parse(await fs.readFile(manifestFile, { encoding: "utf8" }));
@@ -58,13 +41,33 @@ async function checkManifests(pattern) {
5841
if (entry.startsWith("dll-reference")) {
5942
continue;
6043
}
44+
6145
if (!entry.startsWith("./node_modules")) {
6246
throw new AssertionError(`${filename} contains wrongly linked reference ${entry}`);
6347
}
6448
}
49+
50+
if (!filePath.startsWith(pattern + "-")) {
51+
continue;
52+
}
53+
54+
let changed = false;
55+
56+
for (const entry in manifest.content) {
57+
if (entry.startsWith("dll-reference")) {
58+
continue;
59+
}
60+
61+
if (polyfills.some((item) => entry.indexOf(item) !== -1)) {
62+
changed = true;
63+
delete manifest.content[entry];
64+
}
65+
}
66+
67+
if (changed) {
68+
await fs.writeFile(manifestFile, JSON.stringify(manifest, null, 2));
69+
}
6570
}
6671
}
6772

68-
await cleanupManifest("dependencies-prod-manifest.json");
69-
70-
await checkManifests("dependencies*-manifest.json");
73+
await verifyManifests("dependencies");

jest/setupTests.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// INFO: jest-dom matchers leak
12
import matchers from "@testing-library/jest-dom/matchers";
23
import "whatwg-fetch";
34

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@lastui/rocker",
3-
"version": "0.20.6",
3+
"version": "0.20.7",
44
"license": "Apache-2.0",
55
"author": "[email protected]",
66
"homepage": "https://github.com/lastui/rocker#readme",
@@ -63,7 +63,7 @@
6363
],
6464
"scripts": {
6565
"build": "npm run build:dependencies && npm run build:platform && npm run build:bootstrap",
66-
"postbuild": "node ./dependencies/scripts/verify-dlls.mjs && node ./platform/scripts/verify-dlls.mjs && node ./bootstrap/scripts/verify-dlls.mjs",
66+
"postbuild": "node ./scripts/verify-dlls.mjs && node ./cli/index.js lint --fix",
6767
"prebuild:bootstrap": "node ./bootstrap/scripts/link.mjs",
6868
"build:bootstrap": "npm run build:bootstrap:dev && npm run build:bootstrap:prod",
6969
"postbuild:bootstrap": "node ./bootstrap/scripts/unlink.mjs",

platform/scripts/link.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,6 @@ async function linkSelfAsModule() {
5353

5454
await linkDependenciesModules();
5555
await linkDevModule("core-js");
56+
await linkDevModule("tslib");
5657
await linkDLL("dependencies");
5758
await linkSelfAsModule();

platform/scripts/unlink.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ async function unlinkModule(...nodePath) {
2020
}
2121

2222
await unlinkModule("core-js");
23+
await unlinkModule("tslib");
2324
await unlinkModule("@lastui", "rocker", "platform");
2425
await unlinkDLL("dependencies");
2526
await ulinkDependenciesModules();

platform/scripts/verify-dlls.mjs

-70
This file was deleted.

bootstrap/scripts/verify-dlls.mjs scripts/verify-dlls.mjs

+37-32
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,14 @@ import path from "node:path";
44
import { Readable } from "node:stream";
55
import glob from "glob";
66

7-
async function cleanupManifest(filename) {
8-
let changed = false;
9-
10-
const manifestFile = path.resolve(fileURLToPath(import.meta.url), "..", "..", "dll", filename);
11-
const manifest = JSON.parse(await fs.readFile(manifestFile, { encoding: "utf8" }));
12-
13-
const polyfills = [
14-
"./node_modules/regenerator-runtime/",
15-
"./node_modules/@babel/runtime",
16-
"./node_modules/core-js",
17-
"tslib/tslib.es6.js",
18-
];
19-
20-
for (const key in manifest.content) {
21-
if (polyfills.includes(key)) {
22-
changed = true;
23-
delete manifest.content[key];
24-
}
25-
}
26-
if (changed) {
27-
await fs.writeFile(manifestFile, JSON.stringify(manifest, null, 2));
28-
}
29-
}
30-
31-
async function checkManifests(pattern) {
7+
async function verifyManifests(workspace) {
328
const fileStream = new Readable({ objectMode: true });
339
fileStream._read = () => {};
3410

3511
glob(
36-
pattern,
12+
workspace + "*-manifest.json",
3713
{
38-
cwd: path.resolve(fileURLToPath(import.meta.url), "..", "..", "dll"),
14+
cwd: path.resolve(fileURLToPath(import.meta.url), "..", "..", workspace, "dll"),
3915
ignore: [],
4016
},
4117
(error, files) => {
@@ -50,21 +26,50 @@ async function checkManifests(pattern) {
5026
},
5127
);
5228

29+
const polyfills = [
30+
"./node_modules/regenerator-runtime/",
31+
"./node_modules/@babel/runtime",
32+
"./node_modules/core-js",
33+
"./node_modules/tslib",
34+
];
35+
5336
for await (const filePath of fileStream) {
54-
const manifestFile = path.resolve(fileURLToPath(import.meta.url), "..", "..", "dll", filePath);
37+
const manifestFile = path.resolve(fileURLToPath(import.meta.url), "..", "..", workspace, "dll", filePath);
5538
const manifest = JSON.parse(await fs.readFile(manifestFile, { encoding: "utf8" }));
5639

5740
for (const entry in manifest.content) {
5841
if (entry.startsWith("dll-reference")) {
5942
continue;
6043
}
44+
6145
if (!entry.startsWith("./node_modules")) {
62-
throw new AssertionError(`${filename} contains wrongly linked reference ${entry}`);
46+
throw new AssertionError(`${filePath} contains wrongly linked reference ${entry}`);
6347
}
6448
}
49+
50+
if (!filePath.startsWith(workspace + "-")) {
51+
continue;
52+
}
53+
54+
let changed = false;
55+
56+
for (const entry in manifest.content) {
57+
if (entry.startsWith("dll-reference")) {
58+
continue;
59+
}
60+
61+
if (polyfills.some((item) => entry.indexOf(item) !== -1)) {
62+
changed = true;
63+
delete manifest.content[entry];
64+
}
65+
}
66+
67+
if (changed) {
68+
await fs.writeFile(manifestFile, JSON.stringify(manifest, null, 2));
69+
}
6570
}
6671
}
6772

68-
await cleanupManifest("bootstrap-prod-manifest.json");
69-
70-
await checkManifests("bootstrap*-manifest.json");
73+
await verifyManifests("dependencies");
74+
await verifyManifests("platform");
75+
await verifyManifests("bootstrap");

webpack/plugins/ModuleLocalesPlugin.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class ModuleLocalesPlugin {
4545
if (origin.request.indexOf("core-js/") !== -1) {
4646
continue;
4747
}
48-
if (origin.request.endsWith("tslib/tslib.es6.js")) {
48+
if (origin.request.indexOf("tslib/") !== -1) {
4949
continue;
5050
}
5151
if (origin.request.indexOf("regenerator-runtime/") !== -1) {

0 commit comments

Comments
 (0)