From 1d31869a98bdb102ab57cd4ae4bf088ef344bef0 Mon Sep 17 00:00:00 2001 From: Netlify Team Account 1 <90322326+netlify-team-account-1@users.noreply.github.com> Date: Mon, 11 Oct 2021 12:55:01 +0200 Subject: [PATCH] feat: convert small ts files in node_dependencies to ts (#710) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: migrate a bunch of files to typescript * chore: tighten typescript rules * chore: package is a reserved keyword * Update src/runtimes/node/bundlers/esbuild/plugin_native_modules.js Co-authored-by: Eduardo Bouças * Update src/runtimes/node/bundlers/esbuild/plugin_native_modules.js Co-authored-by: Eduardo Bouças * Update src/runtimes/node/bundlers/esbuild/plugin_native_modules.js Co-authored-by: Eduardo Bouças * chore: add gypfile, files and binary fields to PackageJSON * chore: replace module.exports * chore: use export {} Co-authored-by: Netlify Team Account 1 Co-authored-by: Eduardo Bouças Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- .eslintrc.js | 6 ++ package-lock.json | 13 +++++ package.json | 1 + src/deps.d.ts | 7 +++ .../bundlers/esbuild/plugin_native_modules.js | 6 +- .../zisi/{list_imports.js => list_imports.ts} | 18 +++--- .../bundlers/zisi/{nested.js => nested.ts} | 37 ++++++++---- .../zisi/{published.js => published.ts} | 10 ++-- src/runtimes/node/bundlers/zisi/side_files.js | 18 ------ src/runtimes/node/bundlers/zisi/side_files.ts | 18 ++++++ .../zisi/{traverse.js => traverse.ts} | 56 ++++++++++++++----- .../zisi/{tree_shake.js => tree_shake.ts} | 6 +- ...tive_module.js => detect_native_module.ts} | 14 ++++- .../node/utils/{module.js => module.ts} | 6 +- .../{package_json.js => package_json.ts} | 18 +++++- src/runtimes/node/utils/traversal_cache.js | 4 -- src/runtimes/node/utils/traversal_cache.ts | 14 +++++ src/runtimes/rust/builder.js | 6 +- tsconfig.json | 36 ++++++------ 19 files changed, 198 insertions(+), 96 deletions(-) create mode 100644 src/deps.d.ts rename src/runtimes/node/bundlers/zisi/{list_imports.js => list_imports.ts} (74%) rename src/runtimes/node/bundlers/zisi/{nested.js => nested.ts} (76%) rename src/runtimes/node/bundlers/zisi/{published.js => published.ts} (72%) delete mode 100644 src/runtimes/node/bundlers/zisi/side_files.js create mode 100644 src/runtimes/node/bundlers/zisi/side_files.ts rename src/runtimes/node/bundlers/zisi/{traverse.js => traverse.ts} (63%) rename src/runtimes/node/bundlers/zisi/{tree_shake.js => tree_shake.ts} (77%) rename src/runtimes/node/utils/{detect_native_module.js => detect_native_module.ts} (64%) rename src/runtimes/node/utils/{module.js => module.ts} (65%) rename src/runtimes/node/utils/{package_json.js => package_json.ts} (51%) delete mode 100644 src/runtimes/node/utils/traversal_cache.js create mode 100644 src/runtimes/node/utils/traversal_cache.ts diff --git a/.eslintrc.js b/.eslintrc.js index 01b2cd682..99d64d117 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -4,6 +4,12 @@ module.exports = { extends: '@netlify/eslint-config-node', overrides: [ ...overrides, + { + files: '*.ts', + rules: { + 'import/no-namespace': 'off', + }, + }, { files: 'tests/*.js', rules: { diff --git a/package-lock.json b/package-lock.json index 73d26cc97..52633788f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -48,6 +48,7 @@ }, "devDependencies": { "@netlify/eslint-config-node": "^3.3.0", + "@types/semver": "^7.3.8", "adm-zip": "0.5.5", "ava": "^3.0.0", "cpy": "^8.0.0", @@ -1229,6 +1230,12 @@ "integrity": "sha512-//oorEZjL6sbPcKUaCdIGlIUeH26mgzimjBB77G6XRgnDl/L5wOnpyBGRe/Mmf5CVW3PwEBE1NjiMZ/ssFh4wA==", "dev": true }, + "node_modules/@types/semver": { + "version": "7.3.8", + "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.3.8.tgz", + "integrity": "sha512-D/2EJvAlCEtYFEYmmlGwbGXuK886HzyCc3nZX/tkFTQdEU8jZDAgiv08P162yB17y4ZXZoq7yFAnW4GDBb9Now==", + "dev": true + }, "node_modules/@types/unist": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/@types/unist/-/unist-2.0.6.tgz", @@ -13050,6 +13057,12 @@ "integrity": "sha512-//oorEZjL6sbPcKUaCdIGlIUeH26mgzimjBB77G6XRgnDl/L5wOnpyBGRe/Mmf5CVW3PwEBE1NjiMZ/ssFh4wA==", "dev": true }, + "@types/semver": { + "version": "7.3.8", + "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.3.8.tgz", + "integrity": "sha512-D/2EJvAlCEtYFEYmmlGwbGXuK886HzyCc3nZX/tkFTQdEU8jZDAgiv08P162yB17y4ZXZoq7yFAnW4GDBb9Now==", + "dev": true + }, "@types/unist": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/@types/unist/-/unist-2.0.6.tgz", diff --git a/package.json b/package.json index e83032794..3b4f76ab0 100644 --- a/package.json +++ b/package.json @@ -93,6 +93,7 @@ }, "devDependencies": { "@netlify/eslint-config-node": "^3.3.0", + "@types/semver": "^7.3.8", "adm-zip": "0.5.5", "ava": "^3.0.0", "cpy": "^8.0.0", diff --git a/src/deps.d.ts b/src/deps.d.ts new file mode 100644 index 000000000..f38b35fb7 --- /dev/null +++ b/src/deps.d.ts @@ -0,0 +1,7 @@ +declare module 'require-package-name' { + export default function requirePackageName(requireStatement: string): string +} + +declare module 'is-builtin-module' { + export default function isBuiltInModule(moduleName: string): boolean +} diff --git a/src/runtimes/node/bundlers/esbuild/plugin_native_modules.js b/src/runtimes/node/bundlers/esbuild/plugin_native_modules.js index 5fe0e46fa..f6f84cf7c 100644 --- a/src/runtimes/node/bundlers/esbuild/plugin_native_modules.js +++ b/src/runtimes/node/bundlers/esbuild/plugin_native_modules.js @@ -29,15 +29,15 @@ const getNativeModulesPlugin = (externalizedModules) => ({ // eslint-disable-next-line complexity, max-statements build.onResolve({ filter: packageFilter }, async (args) => { - const package = packageName.exec(args.path) + const pkg = packageName.exec(args.path) - if (!package) return + if (!pkg) return let directory = args.resolveDir while (true) { if (path.basename(directory) !== 'node_modules') { - const modulePath = path.join(directory, 'node_modules', package[1]) + const modulePath = path.join(directory, 'node_modules', pkg[1]) const packageJsonPath = path.join(modulePath, 'package.json') // eslint-disable-next-line no-await-in-loop const [isNative, packageJsonData] = await findNativeModule(packageJsonPath, cache) diff --git a/src/runtimes/node/bundlers/zisi/list_imports.js b/src/runtimes/node/bundlers/zisi/list_imports.ts similarity index 74% rename from src/runtimes/node/bundlers/zisi/list_imports.js rename to src/runtimes/node/bundlers/zisi/list_imports.ts index 7f4d4e5d5..636026460 100644 --- a/src/runtimes/node/bundlers/zisi/list_imports.js +++ b/src/runtimes/node/bundlers/zisi/list_imports.ts @@ -1,16 +1,16 @@ -const esbuild = require('@netlify/esbuild') -const isBuiltinModule = require('is-builtin-module') -const { tmpName } = require('tmp-promise') +import * as esbuild from '@netlify/esbuild' +import isBuiltinModule from 'is-builtin-module' +import { tmpName } from 'tmp-promise' -const { JS_BUNDLER_ZISI, RUNTIME_JS } = require('../../../../utils/consts') -const { safeUnlink } = require('../../../../utils/fs') +import { JS_BUNDLER_ZISI, RUNTIME_JS } from '../../../../utils/consts' +import { safeUnlink } from '../../../../utils/fs' // Maximum number of log messages that an esbuild instance will produce. This // limit is important to avoid out-of-memory errors due to too much data being // sent in the Go<>Node IPC channel. const ESBUILD_LOG_LIMIT = 10 -const getListImportsPlugin = ({ imports, path }) => ({ +const getListImportsPlugin = ({ imports, path }: { imports: Set; path: string }): esbuild.Plugin => ({ name: 'list-imports', setup(build) { build.onResolve({ filter: /.*/ }, (args) => { @@ -29,7 +29,7 @@ const getListImportsPlugin = ({ imports, path }) => ({ }, }) -const listImports = async ({ functionName, path }) => { +const listImports = async ({ functionName, path }: { functionName: string; path: string }): Promise => { // We're not interested in the output that esbuild generates, we're just // using it for its parsing capabilities in order to find import/require // statements. However, if we don't give esbuild a path in `outfile`, it @@ -37,7 +37,7 @@ const listImports = async ({ functionName, path }) => { // a temporary file to serve as the esbuild output and then get rid of it // when we're done. const targetPath = await tmpName() - const imports = new Set() + const imports = new Set() try { await esbuild.build({ @@ -64,4 +64,4 @@ const listImports = async ({ functionName, path }) => { return [...imports] } -module.exports = { listImports } +export { listImports } diff --git a/src/runtimes/node/bundlers/zisi/nested.js b/src/runtimes/node/bundlers/zisi/nested.ts similarity index 76% rename from src/runtimes/node/bundlers/zisi/nested.js rename to src/runtimes/node/bundlers/zisi/nested.ts index 909a1f1db..b9e6835c4 100644 --- a/src/runtimes/node/bundlers/zisi/nested.js +++ b/src/runtimes/node/bundlers/zisi/nested.ts @@ -1,9 +1,15 @@ -const { valid: validVersion, validRange, satisfies, gte: greaterThanEqual, ltr: lessThanRange } = require('semver') +import { valid as validVersion, validRange, satisfies, gte as greaterThanEqual, ltr as lessThanRange } from 'semver' + +import { PackageJson } from '../../utils/package_json' // Apply the Node.js module logic recursively on its own dependencies, using // the `package.json` `dependencies`, `peerDependencies` and // `optionalDependencies` keys -const getNestedDependencies = function ({ dependencies = {}, peerDependencies = {}, optionalDependencies = {} }) { +const getNestedDependencies = function ({ + dependencies = {}, + peerDependencies = {}, + optionalDependencies = {}, +}: PackageJson): string[] { return [ ...Object.keys(dependencies), ...Object.keys(peerDependencies).filter(shouldIncludePeerDependency), @@ -14,7 +20,7 @@ const getNestedDependencies = function ({ dependencies = {}, peerDependencies = // Workaround for https://github.com/netlify/zip-it-and-ship-it/issues/73 // TODO: remove this after adding proper modules exclusion as outlined in // https://github.com/netlify/zip-it-and-ship-it/issues/68 -const shouldIncludePeerDependency = function (name) { +const shouldIncludePeerDependency = function (name: string): boolean { return !EXCLUDED_PEER_DEPENDENCIES.has(name) } @@ -42,7 +48,15 @@ const EXCLUDED_PEER_DEPENDENCIES = new Set(['@prisma/cli', 'prisma2', 'prisma']) // `optionalDependencies`: // - are not reported when missing // - are included in module dependencies -const handleModuleNotFound = function ({ error, moduleName, packageJson }) { +const handleModuleNotFound = function ({ + error, + moduleName, + packageJson, +}: { + error: Error & { code: string } + moduleName: string + packageJson: PackageJson +}): [] | never { if ( error.code === 'MODULE_NOT_FOUND' && (isOptionalModule(moduleName, packageJson) || isExternalCrittersModule(moduleName, packageJson)) @@ -54,8 +68,8 @@ const handleModuleNotFound = function ({ error, moduleName, packageJson }) { } const isOptionalModule = function ( - moduleName, - { optionalDependencies = {}, peerDependenciesMeta = {}, peerDependencies = {} }, + moduleName: string, + { optionalDependencies = {}, peerDependenciesMeta = {}, peerDependencies = {} }: PackageJson, ) { return ( optionalDependencies[moduleName] !== undefined || @@ -67,12 +81,15 @@ const isOptionalModule = function ( const MIN_NEXT_VERSION = '10.0.4' -const satisfiesRange = (range) => - validRange(range) && (satisfies(MIN_NEXT_VERSION, range) || lessThanRange(MIN_NEXT_VERSION, range)) +const satisfiesRange = (range: string): boolean => + Boolean(validRange(range)) && (satisfies(MIN_NEXT_VERSION, range) || lessThanRange(MIN_NEXT_VERSION, range)) // 'critters' is used only in Next.js >= 10.0.4 when enabling an experimental option and has to be installed manually // we ignore it if it's missing -const isExternalCrittersModule = function (moduleName, { dependencies = {}, devDependencies = {} }) { +const isExternalCrittersModule = function ( + moduleName: string, + { dependencies = {}, devDependencies = {} }: PackageJson, +) { if (moduleName !== 'critters') { return false } @@ -91,4 +108,4 @@ const isExternalCrittersModule = function (moduleName, { dependencies = {}, devD return satisfiesRange(nextVersion) } -module.exports = { getNestedDependencies, handleModuleNotFound } +export { getNestedDependencies, handleModuleNotFound } diff --git a/src/runtimes/node/bundlers/zisi/published.js b/src/runtimes/node/bundlers/zisi/published.ts similarity index 72% rename from src/runtimes/node/bundlers/zisi/published.js rename to src/runtimes/node/bundlers/zisi/published.ts index 2f1c2e08d..5c7f56cb0 100644 --- a/src/runtimes/node/bundlers/zisi/published.js +++ b/src/runtimes/node/bundlers/zisi/published.ts @@ -1,11 +1,11 @@ -const { promisify } = require('util') +import { promisify } from 'util' -const glob = require('glob') +import glob from 'glob' const pGlob = promisify(glob) // We use all the files published by the Node.js except some that are not needed -const getPublishedFiles = async function (modulePath) { +const getPublishedFiles = async function (modulePath: string): Promise { const ignore = getIgnoredFiles(modulePath) const publishedFiles = await pGlob(`${modulePath}/**`, { ignore, @@ -16,7 +16,7 @@ const getPublishedFiles = async function (modulePath) { return publishedFiles } -const getIgnoredFiles = function (modulePath) { +const getIgnoredFiles = function (modulePath: string): string[] { return IGNORED_FILES.map((ignoreFile) => `${modulePath}/${ignoreFile}`) } @@ -34,4 +34,4 @@ const IGNORED_FILES = [ '*.patch', ] -module.exports = { getPublishedFiles } +export { getPublishedFiles } diff --git a/src/runtimes/node/bundlers/zisi/side_files.js b/src/runtimes/node/bundlers/zisi/side_files.js deleted file mode 100644 index f4d12ea9f..000000000 --- a/src/runtimes/node/bundlers/zisi/side_files.js +++ /dev/null @@ -1,18 +0,0 @@ -const { getPublishedFiles } = require('./published') - -// Some modules generate source files on `postinstall` that are not located -// inside the module's directory itself. -const getSideFiles = function (modulePath, moduleName) { - const sideFiles = SIDE_FILES[moduleName] - if (sideFiles === undefined) { - return [] - } - - return getPublishedFiles(`${modulePath}/${sideFiles}`) -} - -const SIDE_FILES = { - '@prisma/client': '../../.prisma', -} - -module.exports = { getSideFiles } diff --git a/src/runtimes/node/bundlers/zisi/side_files.ts b/src/runtimes/node/bundlers/zisi/side_files.ts new file mode 100644 index 000000000..eccad797a --- /dev/null +++ b/src/runtimes/node/bundlers/zisi/side_files.ts @@ -0,0 +1,18 @@ +import { getPublishedFiles } from './published' + +// Some modules generate source files on `postinstall` that are not located +// inside the module's directory itself. +const getSideFiles = async function (modulePath: string, moduleName: string): Promise { + const sideFiles = SIDE_FILES[moduleName] + if (sideFiles === undefined) { + return [] + } + + return await getPublishedFiles(`${modulePath}/${sideFiles}`) +} + +const SIDE_FILES: Record = { + '@prisma/client': '../../.prisma', +} + +export { getSideFiles } diff --git a/src/runtimes/node/bundlers/zisi/traverse.js b/src/runtimes/node/bundlers/zisi/traverse.ts similarity index 63% rename from src/runtimes/node/bundlers/zisi/traverse.js rename to src/runtimes/node/bundlers/zisi/traverse.ts index a54b810ff..1be899bdf 100644 --- a/src/runtimes/node/bundlers/zisi/traverse.js +++ b/src/runtimes/node/bundlers/zisi/traverse.ts @@ -1,11 +1,13 @@ -const { dirname } = require('path') +import { dirname } from 'path' -const { getModuleName } = require('../../utils/module') +import { getModuleName } from '../../utils/module' +import { PackageJson } from '../../utils/package_json' +import { TraversalCache } from '../../utils/traversal_cache' -const { getNestedDependencies, handleModuleNotFound } = require('./nested') -const { getPublishedFiles } = require('./published') -const { resolvePackage } = require('./resolve') -const { getSideFiles } = require('./side_files') +import { getNestedDependencies, handleModuleNotFound } from './nested' +import { getPublishedFiles } from './published' +import { resolvePackage } from './resolve' +import { getSideFiles } from './side_files' const EXCLUDED_MODULES = new Set(['aws-sdk']) @@ -17,7 +19,13 @@ const getDependencyPathsForDependency = async function ({ state, packageJson, pluginsModulesPath, -}) { +}: { + dependency: string + basedir: string + state: TraversalCache + packageJson: PackageJson + pluginsModulesPath: string +}): Promise { const moduleName = getModuleName(dependency) // Happens when doing require("@scope") (not "@scope/name") or other oddities @@ -33,7 +41,17 @@ const getDependencyPathsForDependency = async function ({ } } -const getDependenciesForModuleName = async function ({ moduleName, basedir, state, pluginsModulesPath }) { +const getDependenciesForModuleName = async function ({ + moduleName, + basedir, + state, + pluginsModulesPath, +}: { + moduleName: string + basedir: string + state: TraversalCache + pluginsModulesPath: string +}): Promise { if (isExcludedModule(moduleName)) { return [] } @@ -55,7 +73,7 @@ const getDependenciesForModuleName = async function ({ moduleName, basedir, stat state.modulePaths.add(modulePath) // The path depends on the user's build, i.e. must be dynamic - // eslint-disable-next-line import/no-dynamic-require, node/global-require + // eslint-disable-next-line import/no-dynamic-require, node/global-require, @typescript-eslint/no-var-requires const packageJson = require(packagePath) const [publishedFiles, sideFiles, depsPaths] = await Promise.all([ @@ -66,11 +84,21 @@ const getDependenciesForModuleName = async function ({ moduleName, basedir, stat return [...publishedFiles, ...sideFiles, ...depsPaths] } -const isExcludedModule = function (moduleName) { +const isExcludedModule = function (moduleName: string): boolean { return EXCLUDED_MODULES.has(moduleName) || moduleName.startsWith('@types/') } -const getNestedModules = async function ({ modulePath, state, packageJson, pluginsModulesPath }) { +const getNestedModules = async function ({ + modulePath, + state, + packageJson, + pluginsModulesPath, +}: { + modulePath: string + state: TraversalCache + packageJson: PackageJson + pluginsModulesPath: string +}) { const dependencies = getNestedDependencies(packageJson) const depsPaths = await Promise.all( @@ -80,9 +108,7 @@ const getNestedModules = async function ({ modulePath, state, packageJson, plugi ) // TODO: switch to Array.flat() once we drop support for Node.js < 11.0.0 // eslint-disable-next-line unicorn/prefer-spread - return [].concat(...depsPaths) + return ([] as string[]).concat(...depsPaths) } -module.exports = { - getDependencyPathsForDependency, -} +export { getDependencyPathsForDependency } diff --git a/src/runtimes/node/bundlers/zisi/tree_shake.js b/src/runtimes/node/bundlers/zisi/tree_shake.ts similarity index 77% rename from src/runtimes/node/bundlers/zisi/tree_shake.js rename to src/runtimes/node/bundlers/zisi/tree_shake.ts index 8474ea5a3..478a37456 100644 --- a/src/runtimes/node/bundlers/zisi/tree_shake.js +++ b/src/runtimes/node/bundlers/zisi/tree_shake.ts @@ -1,4 +1,4 @@ -const { getModuleName } = require('../../utils/module') +import { getModuleName } from '../../utils/module' const LOCAL_IMPORT_REGEXP = /^(\.|\/)/ @@ -7,7 +7,7 @@ const LOCAL_IMPORT_REGEXP = /^(\.|\/)/ // 1. doing dynamic requires (e.g. require(dynamicPath)) // 2. reading files (e.g. fs.readFileSync(someNonJsFile)) // an exception is when the function was generated by `next-on-netlify` to avoid bundling the entire `Next.js` framework -const shouldTreeShake = function (dependency, treeShakeNext) { +const shouldTreeShake = function (dependency: string, treeShakeNext: boolean): boolean { if (LOCAL_IMPORT_REGEXP.test(dependency)) { return true } @@ -15,4 +15,4 @@ const shouldTreeShake = function (dependency, treeShakeNext) { return treeShakeNext && getModuleName(dependency) === 'next' } -module.exports = { shouldTreeShake } +export { shouldTreeShake } diff --git a/src/runtimes/node/utils/detect_native_module.js b/src/runtimes/node/utils/detect_native_module.ts similarity index 64% rename from src/runtimes/node/utils/detect_native_module.js rename to src/runtimes/node/utils/detect_native_module.ts index e87303f75..d3920846d 100644 --- a/src/runtimes/node/utils/detect_native_module.js +++ b/src/runtimes/node/utils/detect_native_module.ts @@ -1,8 +1,16 @@ -const { extname } = require('path') +import { extname } from 'path' + +import { PackageJson } from './package_json' const markerModules = ['bindings', 'nan', 'node-gyp', 'node-gyp-build', 'node-pre-gyp', 'prebuild'] -const isNativeModule = ({ binary, dependencies = {}, devDependencies = {}, files = [], gypfile }) => { +const isNativeModule = ({ + binary, + dependencies = {}, + devDependencies = {}, + files = [], + gypfile, +}: PackageJson): boolean => { if (binary || gypfile) { return true } @@ -18,4 +26,4 @@ const isNativeModule = ({ binary, dependencies = {}, devDependencies = {}, files return hasBinaryFile } -module.exports = { isNativeModule } +export { isNativeModule } diff --git a/src/runtimes/node/utils/module.js b/src/runtimes/node/utils/module.ts similarity index 65% rename from src/runtimes/node/utils/module.js rename to src/runtimes/node/utils/module.ts index a4183882e..ac6cc6920 100644 --- a/src/runtimes/node/utils/module.js +++ b/src/runtimes/node/utils/module.ts @@ -1,13 +1,13 @@ -const requirePackageName = require('require-package-name') +import requirePackageName from 'require-package-name' // Windows path normalization const BACKSLASH_REGEXP = /\\/g // When doing require("moduleName/file/path"), only keep `moduleName` -const getModuleName = function (dependency) { +const getModuleName = function (dependency: string): string { const dependencyA = dependency.replace(BACKSLASH_REGEXP, '/') const moduleName = requirePackageName(dependencyA) return moduleName } -module.exports = { getModuleName } +export { getModuleName } diff --git a/src/runtimes/node/utils/package_json.js b/src/runtimes/node/utils/package_json.ts similarity index 51% rename from src/runtimes/node/utils/package_json.js rename to src/runtimes/node/utils/package_json.ts index 0a60cb77f..8098aba38 100644 --- a/src/runtimes/node/utils/package_json.js +++ b/src/runtimes/node/utils/package_json.ts @@ -1,7 +1,19 @@ -const pkgDir = require('pkg-dir') +import pkgDir from 'pkg-dir' + +interface PackageJson { + name?: string + dependencies?: Record + peerDependencies?: Record + peerDependenciesMeta?: Record + optionalDependencies?: Record + devDependencies?: Record + files?: string[] + gypfile?: boolean + binary?: boolean +} // Retrieve the `package.json` of a specific project or module -const getPackageJson = async function (srcDir) { +const getPackageJson = async function (srcDir: string): Promise { const packageRoot = await pkgDir(srcDir) if (packageRoot === undefined) { @@ -18,4 +30,4 @@ const getPackageJson = async function (srcDir) { } } -module.exports = { getPackageJson } +export { getPackageJson, PackageJson } diff --git a/src/runtimes/node/utils/traversal_cache.js b/src/runtimes/node/utils/traversal_cache.js deleted file mode 100644 index 8c6562ce2..000000000 --- a/src/runtimes/node/utils/traversal_cache.js +++ /dev/null @@ -1,4 +0,0 @@ -// Local cache used for optimizing the traversal of module dependencies. -const getNewCache = () => ({ localFiles: new Set(), moduleNames: new Set(), modulePaths: new Set() }) - -module.exports = { getNewCache } diff --git a/src/runtimes/node/utils/traversal_cache.ts b/src/runtimes/node/utils/traversal_cache.ts new file mode 100644 index 000000000..b4771197b --- /dev/null +++ b/src/runtimes/node/utils/traversal_cache.ts @@ -0,0 +1,14 @@ +// Local cache used for optimizing the traversal of module dependencies. +interface TraversalCache { + localFiles: Set + moduleNames: Set + modulePaths: Set +} + +const getNewCache = (): TraversalCache => ({ + localFiles: new Set(), + moduleNames: new Set(), + modulePaths: new Set(), +}) + +export { TraversalCache, getNewCache } diff --git a/src/runtimes/rust/builder.js b/src/runtimes/rust/builder.js index f6feaf9a5..16b5eef33 100644 --- a/src/runtimes/rust/builder.js +++ b/src/runtimes/rust/builder.js @@ -34,8 +34,10 @@ const build = async ({ config, name, srcDir }) => { // must extract the crate name from the manifest and use it to form the path // to the binary. const manifest = await pReadFile(join(srcDir, MANIFEST_NAME)) - const { package } = toml.parse(manifest) - const binaryPath = join(targetDirectory, BUILD_TARGET, 'release', package.name) + const { + package: { name: packageName }, + } = toml.parse(manifest) + const binaryPath = join(targetDirectory, BUILD_TARGET, 'release', packageName) const stat = await lstat(binaryPath) return { diff --git a/tsconfig.json b/tsconfig.json index 070944780..2e598aee0 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -73,25 +73,25 @@ "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */, /* Type Checking */ - "strict": false /* Enable all strict type-checking options. */, - "noImplicitAny": false /* Enable error reporting for expressions and declarations with an implied `any` type.. */, - "strictNullChecks": false /* When type checking, take into account `null` and `undefined`. */, - "strictFunctionTypes": false /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */, - "strictBindCallApply": false /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */, - "strictPropertyInitialization": false /* Check for class properties that are declared but not set in the constructor. */, - "noImplicitThis": false /* Enable error reporting when `this` is given the type `any`. */, + "strict": true /* Enable all strict type-checking options. */, + // "noImplicitAny": false /* Enable error reporting for expressions and declarations with an implied `any` type.. */, + // "strictNullChecks": false /* When type checking, take into account `null` and `undefined`. */, + // "strictFunctionTypes": false /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */, + // "strictBindCallApply": false /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */, + // "strictPropertyInitialization": false /* Check for class properties that are declared but not set in the constructor. */, + // "noImplicitThis": false /* Enable error reporting when `this` is given the type `any`. */, "useUnknownInCatchVariables": false /* Type catch clause variables as 'unknown' instead of 'any'. */, - "alwaysStrict": false /* Ensure 'use strict' is always emitted. */, - "noUnusedLocals": false /* Enable error reporting when a local variables aren't read. */, - "noUnusedParameters": false /* Raise an error when a function parameter isn't read */, - "exactOptionalPropertyTypes": false /* Interpret optional property types as written, rather than adding 'undefined'. */, - "noImplicitReturns": false /* Enable error reporting for codepaths that do not explicitly return in a function. */, - "noFallthroughCasesInSwitch": false /* Enable error reporting for fallthrough cases in switch statements. */, - "noUncheckedIndexedAccess": false /* Include 'undefined' in index signature results */, - "noImplicitOverride": false /* Ensure overriding members in derived classes are marked with an override modifier. */, - "noPropertyAccessFromIndexSignature": false /* Enforces using indexed accessors for keys declared using an indexed type */, - "allowUnusedLabels": false /* Disable error reporting for unused labels. */, - "allowUnreachableCode": false /* Disable error reporting for unreachable code. */, + // "alwaysStrict": false /* Ensure 'use strict' is always emitted. */, + // "noUnusedLocals": false /* Enable error reporting when a local variables aren't read. */, + // "noUnusedParameters": false /* Raise an error when a function parameter isn't read */, + // "exactOptionalPropertyTypes": false /* Interpret optional property types as written, rather than adding 'undefined'. */, + // "noImplicitReturns": false /* Enable error reporting for codepaths that do not explicitly return in a function. */, + // "noFallthroughCasesInSwitch": false /* Enable error reporting for fallthrough cases in switch statements. */, + // "noUncheckedIndexedAccess": false /* Include 'undefined' in index signature results */, + // "noImplicitOverride": false /* Ensure overriding members in derived classes are marked with an override modifier. */, + // "noPropertyAccessFromIndexSignature": false /* Enforces using indexed accessors for keys declared using an indexed type */, + // "allowUnusedLabels": false /* Disable error reporting for unused labels. */, + // "allowUnreachableCode": false /* Disable error reporting for unreachable code. */, /* Completeness */ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */