Module-Starter ESM Migration

Summary: Ref T2858

Reviewers: #testers, kuba-orlik

Reviewed By: #testers, kuba-orlik

Maniphest Tasks: T2858

Differential Revision: https://hub.sealcode.org/D1662
master
JayNecessary 4 weeks ago
parent d6b4dbca6f
commit 0fc53b26d8

@ -1,7 +1,11 @@
const { build } = require("esbuild"); import * as esbuild from "esbuild";
const glob = require("tiny-glob"); import { default as glob } from "tiny-glob";
const { promises: fs } = require("node:fs"); import { promises as fs } from "node:fs";
const { extname, resolve, relative } = require("node:path"); import { extname, resolve, relative, dirname } from "node:path";
import { fileURLToPath } from "node:url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const watch = process.argv.at(-1) === "--watch"; const watch = process.argv.at(-1) === "--watch";
@ -40,15 +44,24 @@ const handle_absolute_paths = (project_dir) => ({
let entryPoints = Object.fromEntries( let entryPoints = Object.fromEntries(
(await glob("./src/**/*.ts")).map((e) => [e.replace(/\.ts$/, ""), e]) (await glob("./src/**/*.ts")).map((e) => [e.replace(/\.ts$/, ""), e])
); );
build({
const buildOptions = {
entryPoints, entryPoints,
sourcemap: true, sourcemap: true,
bundle: false,
outdir: "./lib", outdir: "./lib",
logLevel: "info", logLevel: "info",
platform: "node", platform: "node",
watch, target: "es2022",
target: "node16",
format: "esm", format: "esm",
plugins: [handle_absolute_paths(__dirname)], plugins: [handle_absolute_paths(__dirname)],
}); };
if (watch) {
const context = await esbuild.context(buildOptions);
await context.watch();
} else {
await esbuild.build(buildOptions);
}
})(); })();

@ -3,8 +3,14 @@
"version": "0.0.1", "version": "0.0.1",
"description": "module template", "description": "module template",
"main": "lib/src/index.js", "main": "lib/src/index.js",
"exports": {
".": {
"types": "./@types/index.d.ts",
"default": "./lib/src/index.js"
}
},
"scripts": { "scripts": {
"build": "node ./esbuild.cjs", "build": "node ./esbuild.js",
"prepare": "rm -rf @types && npm run typecheck && npm run build-declarations && npm run build", "prepare": "rm -rf @types && npm run typecheck && npm run build-declarations && npm run build",
"pretest": "npm run build", "pretest": "npm run build",
"test": "node test.cjs", "test": "node test.cjs",

@ -13,6 +13,7 @@ let mocha_options = [
"--timeout=10000", "--timeout=10000",
"--require", "--require",
"source-map-support/register", "source-map-support/register",
"--exit",
]; ];
if (args["test-report"]) { if (args["test-report"]) {

@ -1,7 +1,7 @@
{ {
"compilerOptions": { "compilerOptions": {
"module": "commonjs", "module": "nodenext",
"moduleResolution": "node", "moduleResolution": "nodenext",
"noImplicitAny": true, "noImplicitAny": true,
"noImplicitThis": true, "noImplicitThis": true,
"strictNullChecks": true, "strictNullChecks": true,

Loading…
Cancel
Save