From e6302741dcc6efd91bd23011702e8a0bfccfd3f4 Mon Sep 17 00:00:00 2001 From: Eduard Marbach Date: Wed, 9 Oct 2024 16:27:26 +0200 Subject: [PATCH] refactor: remove unused esbuild stuff --- build.js | 11 ------- cjs-shim.ts | 7 ---- native_modules/README.adoc | 3 -- native_modules/detector.js | 19 ----------- native_modules/plugin.js | 67 -------------------------------------- 5 files changed, 107 deletions(-) delete mode 100644 build.js delete mode 100644 cjs-shim.ts delete mode 100644 native_modules/README.adoc delete mode 100644 native_modules/detector.js delete mode 100644 native_modules/plugin.js diff --git a/build.js b/build.js deleted file mode 100644 index 3e965d6..0000000 --- a/build.js +++ /dev/null @@ -1,11 +0,0 @@ -import { commonjs } from "@hyrious/esbuild-plugin-commonjs"; -import { build } from "esbuild"; - -build({ - entryPoints: ["index.ts"], - bundle: true, - format: "esm", - external: ["fs", "child_process", "crypto", "os", "path"], - outfile: "out.js", - plugins: [commonjs()], -}).catch(() => process.exit(1)); diff --git a/cjs-shim.ts b/cjs-shim.ts deleted file mode 100644 index 7d7bbfd..0000000 --- a/cjs-shim.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { createRequire } from "node:module"; -import path from "node:path"; -import url from "node:url"; - -globalThis.require = createRequire(import.meta.url); -globalThis.__filename = url.fileURLToPath(import.meta.url); -globalThis.__dirname = path.dirname(__filename); diff --git a/native_modules/README.adoc b/native_modules/README.adoc deleted file mode 100644 index 0b1d5b6..0000000 --- a/native_modules/README.adoc +++ /dev/null @@ -1,3 +0,0 @@ -# https://esbuild.github.io/plugins/[esbuild plugin] to handle https://nodejs.org/dist/latest-v16.x/docs/api/addons.html[NodeJS native modules] - -The source code here was shamelessly taken directly from the https://github.com/netlify/zip-it-and-ship-it/tree/v4.23.6/src/runtimes/node/native_modules[Netlify zip-it-and-ship-it repository]. diff --git a/native_modules/detector.js b/native_modules/detector.js deleted file mode 100644 index 2d7ecb8..0000000 --- a/native_modules/detector.js +++ /dev/null @@ -1,19 +0,0 @@ -import { extname } from 'node:path'; - -const markerModules = ['bindings', 'nan', 'node-gyp', 'node-gyp-build', 'node-pre-gyp', 'prebuild'] - -export const isNativeModule = ({ binary, dependencies = {}, devDependencies = {}, files = [], gypfile }) => { - if (binary || gypfile) { - return true - } - - const hasMarkerModule = markerModules.some((marker) => dependencies[marker] || devDependencies[marker]) - - if (hasMarkerModule) { - return true - } - - const hasBinaryFile = files.some((path) => !path.startsWith('!') && extname(path) === '.node') - - return hasBinaryFile -} diff --git a/native_modules/plugin.js b/native_modules/plugin.js deleted file mode 100644 index a94f181..0000000 --- a/native_modules/plugin.js +++ /dev/null @@ -1,67 +0,0 @@ -import path from 'node:path'; - -import readPackageJson from 'read-package-json-fast'; - -import { isNativeModule } from './detector.js'; - -// Filters out relative or absolute file paths. -const packageFilter = /^([^./]*)$/ - -// Filters valid package names and extracts the base directory. -const packageName = /^([^@][^/]*|@[^/]*\/[^/]+)(?:\/|$)/ - -const findNativeModule = (packageJsonPath, cache) => { - if (cache[packageJsonPath] === undefined) { - cache[packageJsonPath] = readPackageJson(packageJsonPath).then( - (data) => [Boolean(isNativeModule(data), data), data], - () => [], - ) - } - - return cache[packageJsonPath] -} - -export const externalNativeModulesPlugin = (externalizedModules) => ({ - name: 'external-native-modules', - setup(build) { - const cache = {} - - build.onResolve({ filter: packageFilter }, async (args) => { - const packageJson = packageName.exec(args.path) - - if (!packageJson) return - - let directory = args.resolveDir - - while (true) { - if (path.basename(directory) !== 'node_modules') { - const modulePath = path.join(directory, 'node_modules', packageJson[1]) - const packageJsonPath = path.join(modulePath, 'package.json') - const [isNative, packageJsonData] = await findNativeModule(packageJsonPath, cache) - - if (isNative === true) { - if (externalizedModules[args.path] === undefined) { - externalizedModules[args.path] = {} - } - - externalizedModules[args.path][modulePath] = packageJsonData.version - - return { path: args.path, external: true } - } - - if (isNative === false) { - return - } - } - - const parentDirectory = path.dirname(directory) - - if (parentDirectory === directory) { - break - } - - directory = parentDirectory - } - }) - }, -})