Skip to content

Commit 756437b

Browse files
authored
fix: patch __spreadArray helper to work around tslib bug (#4481) (#4575)
1 parent 172a416 commit 756437b

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"hydrate/"
1717
],
1818
"scripts": {
19-
"build": "npm run util:copy-icons && stencil build",
19+
"build": "npm run util:copy-icons && stencil build && npm run util:patch-es5-helpers",
2020
"build:watch": "npm run util:copy-icons && stencil build --watch",
2121
"build:watch-dev": "npm run util:copy-icons && stencil build --dev --watch",
2222
"build-storybook": "npm run util:copy-icons && stencil build --config stencil.config.ts && build-storybook --static-dir ./www --output-dir ./docs",
@@ -48,6 +48,7 @@
4848
"util:copy-icons": "cpy \"./node_modules/@esri/calcite-ui-icons/js/*.json\" \"./src/components/icon/assets/icon/\" --flat",
4949
"util:deploy-next": "npm run util:prep-next && npm run util:push-tags && npm run util:publish-next",
5050
"util:deploy-next-from-ci": "ts-node --project ./tsconfig-node-scripts.json support/deployNextFromCI.ts",
51+
"util:patch-es5-helpers": "ts-node support/patchES5Helpers.ts",
5152
"util:prep-next": "ts-node --project ./tsconfig-node-scripts.json support/prepReleaseCommit.ts --next && npm run build",
5253
"util:publish-next": "npm publish --tag next",
5354
"util:check-squash-mergeable-branch": "ts-node --project ./tsconfig-node-scripts.json support/checkSquashMergeableBranch.ts",

support/patchES5Helpers.ts

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const {
2+
promises: { readFile, readdir, writeFile }
3+
} = require("fs");
4+
const { normalize } = require("path");
5+
const { quote } = require("shell-quote");
6+
7+
(async function () {
8+
const esmEs5Output = quote([normalize(`${__dirname}/../dist/esm-es5/`)]);
9+
10+
// we patch __spreadArray to work around https://github.com/microsoft/tslib/issues/175
11+
// see https://github.com/Esri/calcite-components/issues/4481#issuecomment-1128336510 for more info
12+
const spreadArrayHelperToken =
13+
/(var __spreadArray\=this\&\&this\.__spreadArray\|\|function\(\w\,)(\w)(\,\w\)\{)(if\((?:\w)\|\|arguments\.length\=\=\=2\))/;
14+
const patchedSpreadArrayReplacement = '$1$2$3if(typeof $2 === "string"){$2=Array.prototype.slice.call($2)}$4';
15+
const files = await readdir(esmEs5Output);
16+
17+
try {
18+
for (const file of files) {
19+
const filePath = quote([normalize(`${esmEs5Output}/${file}`)]);
20+
const contents = await readFile(filePath, { encoding: "utf8" });
21+
await writeFile(filePath, contents.replace(spreadArrayHelperToken, patchedSpreadArrayReplacement));
22+
}
23+
} catch (err) {
24+
console.error(err);
25+
process.exit(1);
26+
}
27+
})();

0 commit comments

Comments
 (0)