Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump parse-imports #38

Merged
merged 2 commits into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": "bin/run.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 @@ -51,7 +51,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 @@ -65,12 +65,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