Skip to content

Commit

Permalink
ref(typescript): Remove resolve package
Browse files Browse the repository at this point in the history
@rollup/plugin-typescript requires Node 14 or higher, so we can switch
from using the resolve package to built-in `require.resolve`.
  • Loading branch information
AbhiPrasad committed Jun 29, 2024
1 parent 8550c4b commit d361085
Show file tree
Hide file tree
Showing 3 changed files with 5,117 additions and 4,228 deletions.
3 changes: 1 addition & 2 deletions packages/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@
}
},
"dependencies": {
"@rollup/pluginutils": "^5.1.0",
"resolve": "^1.22.1"
"@rollup/pluginutils": "^5.1.0"
},
"devDependencies": {
"@rollup/plugin-buble": "^1.0.0",
Expand Down
20 changes: 6 additions & 14 deletions packages/typescript/src/tslib.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
import { fileURLToPath } from 'url';

import type { SyncOpts } from 'resolve';
import resolve from 'resolve';

// const resolveIdAsync = (file: string, opts: AsyncOpts) =>
// new Promise<string>((fulfil, reject) =>
// resolveId(file, opts, (err, contents) =>
// err || typeof contents === 'undefined' ? reject(err) : fulfil(contents)
// )
// );

const resolveId = (file: string, opts: SyncOpts) => resolve.sync(file, opts);
import { createRequire } from 'module';

/**
* Returns code asynchronously for the tslib helper library.
*/
export const getTsLibPath = () => {
// @ts-ignore import.meta.url is allowed because the Rollup plugin injects the correct module format
const require = createRequire(import.meta.url);
// Note: This isn't preferable, but we've no other way to test this bit. Removing the tslib devDep
// during the test run doesn't work due to the nature of the pnpm flat node_modules, and
// other workspace dependencies that depenend upon tslib.
try {
// eslint-disable-next-line no-underscore-dangle
return resolveId(process.env.__TSLIB_TEST_PATH__ || 'tslib/tslib.es6.js', {
// @ts-ignore import.meta.url is allowed because the Rollup plugin injects the correct module format
basedir: fileURLToPath(new URL('.', import.meta.url))
return require.resolve(process.env.__TSLIB_TEST_PATH__ || 'tslib/tslib.es6.js', {
// @ts-ignore See import.meta.url above
paths: [fileURLToPath(new URL('.', import.meta.url))]
});
} catch (_) {
return null;
Expand Down
Loading

0 comments on commit d361085

Please sign in to comment.