Skip to content

Commit

Permalink
chore: bump parse-imports
Browse files Browse the repository at this point in the history
  • Loading branch information
TomerAberbach committed Jun 3, 2021
1 parent a489715 commit 5f3a609
Show file tree
Hide file tree
Showing 3 changed files with 753 additions and 615 deletions.
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"main": "lib/index.js",
"scripts": {
"lint": "eslint . --ext=.js,.ts,.json",
"test": "jest"
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest"
},
"oclif": {
"bin": "dowdep",
Expand Down Expand Up @@ -48,7 +48,7 @@
"ntqdm": "^1.0.0",
"oclif": "^1.18.0",
"package-metadata": "^1.1.2",
"parse-imports": "^0.0.5",
"parse-imports": "^1.0.0",
"path": "^0.12.7",
"ts-node": "^10.0.0",
"tslib": "^2",
Expand All @@ -62,12 +62,13 @@
"@types/rimraf": "^3.0.0",
"@typescript-eslint/eslint-plugin": "^4.26.0",
"@typescript-eslint/parser": "^4.26.0",
"cross-env": "^7.0.3",
"eslint": "^7.27.0",
"eslint-plugin-jest": "^24.3.6",
"jest": "^26.6.3",
"jest": "^27.0.0-next.11",
"package-json": "^6.5.0",
"read-package-json": "^3.0.1",
"rimraf": "^3.0.0",
"ts-jest": "^26.5.6"
"ts-jest": "^27.0.0-next.12"
}
}
12 changes: 11 additions & 1 deletion src/references.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import glob from 'glob-promise'
import asyncIteratorToArray from 'it-all'
import _ from "lodash"
import tqdm from 'ntqdm'
import parseImports from 'parse-imports'
import path from 'path'

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

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

return await parseImports(source)
} catch (parseError) {
console.warn("Error from parse-imports", { parseError, source: source.slice(0, 100) })
Expand Down
Loading

0 comments on commit 5f3a609

Please sign in to comment.