Skip to content

Commit 189aaa5

Browse files
committed
deps: upgrade tslib to 2.4.0, remove @yarn-tool/resolve-package
- tslib 2.4.0 is forward and backward-compatible with older and newer Node exports mechanisms, so the Node 17 error should no longer be present - it has the older `./` and the newer `./*` in its package exports, which should allow for `package.json` to be read in both older and newer implementations - this allows us to remove the extra dep on `@yarn-tool/resolve-package` as well - other than less unnecessary deps being good, `@yarn-tool/resolve-package` is also a not well-documented package with very few users, which does not make for a good security posture for rpt2 (which has historically prioritized supply chain security in other issues around deps) or, in particular, its consumers, which there are very many of (in contrast with `@yarn-tool`) - per my issue comment, we could also have avoided the extra dep prior to the tslib upgrade by resolving to absolute paths, as Node only does a "weak" encapsulation of relative imports - test: add a small unit test for tslib.ts to ensure that this method works and passes on different Node versions in CI - more a smoke test that it runs at all, the testing is additional and a bit duplicative of the source tbh
1 parent 56716de commit 189aaa5

File tree

4 files changed

+63
-15
lines changed

4 files changed

+63
-15
lines changed

__tests__/tslib.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { test, expect } from "@jest/globals";
2+
import * as fs from "fs-extra";
3+
4+
import { tslibVersion, tslibSource } from "../src/tslib";
5+
6+
test("tslib", async () => {
7+
expect(tslibVersion).toEqual(require("tslib/package.json").version);
8+
9+
const tslibES6 = await fs.readFile(require.resolve("tslib/tslib.es6.js"), "utf8");
10+
expect(tslibSource).toEqual(tslibES6);
11+
});

package-lock.json

Lines changed: 48 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,10 @@
3333
},
3434
"dependencies": {
3535
"@rollup/pluginutils": "^4.1.2",
36-
"@yarn-tool/resolve-package": "^1.0.40",
3736
"find-cache-dir": "^3.3.2",
3837
"fs-extra": "^10.0.0",
3938
"resolve": "^1.20.0",
40-
"tslib": "^2.3.1"
39+
"tslib": "^2.4.0"
4140
},
4241
"peerDependencies": {
4342
"rollup": ">=1.26.3",

src/tslib.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ export const TSLIB = "tslib";
55
export const TSLIB_VIRTUAL = "\0tslib.js";
66
export let tslibSource: string;
77
export let tslibVersion: string;
8+
89
try
910
{
1011
// tslint:disable-next-line:no-string-literal no-var-requires
11-
const _ = require("@yarn-tool/resolve-package").resolvePackage('tslib');
12-
const tslibPackage = _.pkg;
13-
const tslibPath = _.resolveLocation(tslibPackage.module);
12+
const tslibPackage = require("tslib/package.json");
13+
const tslibPath = require.resolve("tslib/" + tslibPackage.module);
1414
tslibSource = readFileSync(tslibPath, "utf8");
1515
tslibVersion = tslibPackage.version;
1616
} catch (e)

0 commit comments

Comments
 (0)