Skip to content

Commit 5f3a609

Browse files
committed
chore: bump parse-imports
1 parent a489715 commit 5f3a609

File tree

3 files changed

+753
-615
lines changed

3 files changed

+753
-615
lines changed

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"main": "lib/index.js",
2020
"scripts": {
2121
"lint": "eslint . --ext=.js,.ts,.json",
22-
"test": "jest"
22+
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest"
2323
},
2424
"oclif": {
2525
"bin": "dowdep",
@@ -48,7 +48,7 @@
4848
"ntqdm": "^1.0.0",
4949
"oclif": "^1.18.0",
5050
"package-metadata": "^1.1.2",
51-
"parse-imports": "^0.0.5",
51+
"parse-imports": "^1.0.0",
5252
"path": "^0.12.7",
5353
"ts-node": "^10.0.0",
5454
"tslib": "^2",
@@ -62,12 +62,13 @@
6262
"@types/rimraf": "^3.0.0",
6363
"@typescript-eslint/eslint-plugin": "^4.26.0",
6464
"@typescript-eslint/parser": "^4.26.0",
65+
"cross-env": "^7.0.3",
6566
"eslint": "^7.27.0",
6667
"eslint-plugin-jest": "^24.3.6",
67-
"jest": "^26.6.3",
68+
"jest": "^27.0.0-next.11",
6869
"package-json": "^6.5.0",
6970
"read-package-json": "^3.0.1",
7071
"rimraf": "^3.0.0",
71-
"ts-jest": "^26.5.6"
72+
"ts-jest": "^27.0.0-next.12"
7273
}
7374
}

src/references.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import glob from 'glob-promise'
55
import asyncIteratorToArray from 'it-all'
66
import _ from "lodash"
77
import tqdm from 'ntqdm'
8-
import parseImports from 'parse-imports'
98
import path from 'path'
109

1110
import { getCacheDirectory } from './npm-deps'
@@ -180,6 +179,17 @@ class PackageReferenceSearcher {
180179

181180
const imports = await (async () => {
182181
try {
182+
// Truly awful hack! There are a few things going on here:
183+
// - Jest (or something) can't find parse-imports by just importing its package name
184+
// no matter what. Just give it the path to the src/index.js file
185+
// - TypeScript will always try to replace dynamic imports with requires
186+
// which doesn't work for importing ESM from CJS (https://github.com/microsoft/TypeScript/issues/43329).
187+
// We work around by "hiding" our dynamic import in a Function constructor (terrible...)
188+
// - All of this required jest@next, ts-jest@next, AND `NODE_OPTIONS=--experimental-vm-modules`
189+
const parseImportsIndexPath = path.join(path.dirname(__dirname), 'node_modules/parse-imports/src/index.js')
190+
const dynamicImport = new Function('moduleName', 'return import(moduleName)')
191+
const parseImports = (await dynamicImport(parseImportsIndexPath)).default
192+
183193
return await parseImports(source)
184194
} catch (parseError) {
185195
console.warn("Error from parse-imports", { parseError, source: source.slice(0, 100) })

0 commit comments

Comments
 (0)