Skip to content
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
8 changes: 8 additions & 0 deletions .changes/esm-only.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@simulacrum/server": minor:enhance
"@simulacrum/foundation-simulator": minor:enhance
"@simulacrum/auth0-simulator": minor:enhance
"@simulacrum/github-api-simulator": minor:enhance
---

Convert package to ESM only. All LTS are able to import ESM, both from an ESM or CJS context.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@
"tsc": "pnpm -r --if-present run tsc"
},
"devDependencies": {
"@arethetypeswrong/core": "^0.18.3",
"@types/node": "^24.0.0",
"oxfmt": "^0.43.0",
"oxlint": "^1.58.0",
"tsdown": "^0.21.7",
"publint": "^0.3.21",
"tsdown": "^0.22.2",
"typescript": "5.8.3",
"unplugin-unused": "^0.5.7",
"vitest": "^3.2.4"
},
"engines": {
Expand Down
6 changes: 3 additions & 3 deletions packages/auth0/bin/start.cjs → packages/auth0/bin/start.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env node
const auth0APIsimulator = require("../dist/index.cjs");
import { simulation, defaultUser } from "../dist/index.mjs";

const app = auth0APIsimulator.simulation();
const app = simulation();
app.listen(4400, () =>
console.log(
`Auth0 simulation server started at https://localhost:4400\n` +
`Visit the root route to view all available routes.\n\n` +
`Point your configuration at this simulation server and use the default user below.\n` +
`Email: ${auth0APIsimulator.defaultUser.email}\nPassword: ${auth0APIsimulator.defaultUser.password}\n` +
`Email: ${defaultUser.email}\nPassword: ${defaultUser.password}\n` +
`\nPress Ctrl+C to stop the server`,
),
);
12 changes: 3 additions & 9 deletions packages/auth0/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@
"type": "git",
"url": "git+https://github.com/thefrontside/simulacrum.git"
},
"bin": "bin/start.cjs",
"bin": "bin/start.mjs",
"files": [
"bin/**/*",
"dist/**/*"
],
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.cts",
"typesVersions": {
"*": {
Expand All @@ -42,17 +40,13 @@
"exports": {
".": {
"development": "./src/index.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
"default": "./dist/index.mjs"
},
"./package.json": "./package.json"
},
"publishConfig": {
"exports": {
".": {
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
},
".": "./dist/index.mjs",
"./package.json": "./package.json"
}
},
Expand Down
4 changes: 2 additions & 2 deletions packages/auth0/src/rules/parse-rules-files.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { extensionlessFileName } from "./extensionless-file-name.ts";
import { assert } from "assert-ts";
import fs from "fs";
import path from "path";
import fs from "node:fs";
import path from "node:path";

export function parseRulesFiles(rulesPath: string): { code: string; filename: string }[] {
let ruleFiles = fs.readdirSync(rulesPath).filter((f) => path.extname(f) === ".js");
Expand Down
29 changes: 17 additions & 12 deletions packages/auth0/src/rules/rules-runner.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import path from "path";
import vm from "vm";
import fs from "fs";
import { createRequire } from "node:module";
import { assert } from "assert-ts";
import { parseRulesFiles } from "./parse-rules-files.ts";
import type { Rule, RuleContext, RuleUser } from "./types.ts";

export type RulesRunner = <A, I>(user: RuleUser, context: RuleContext<A, I>) => void;

const require = createRequire(import.meta.url);

async function runRule<A, I>(user: RuleUser, context: RuleContext<A, I>, rule: Rule) {
await new Promise((resolve, reject) => {
await new Promise<void>((resolve, reject) => {
let sandbox = {
process,
Buffer,
Expand All @@ -21,7 +24,7 @@ async function runRule<A, I>(user: RuleUser, context: RuleContext<A, I>, rule: R
setTimeout,
console,
require,
module,
importMeta: import.meta,
resolve,
reject,
__simulator: {
Expand All @@ -37,16 +40,18 @@ async function runRule<A, I>(user: RuleUser, context: RuleContext<A, I>, rule: R

console.debug(`executing rule ${path.basename(filename)}`);

let script = new vm.Script(`
(async function(exports) {
try {
await (${code})(__simulator.user, __simulator.context, resolve);
} catch (err) {
console.error(err);
reject();
}
})(module.exports)
`);
let script = new vm.Script(
`
(async function runRule() {
try {
await (${code})(__simulator.user, __simulator.context, resolve);
} catch (err) {
console.error(err);
reject(err);
}
})();
`,
);

script.runInContext(vmContext, {
filename,
Expand Down
4 changes: 2 additions & 2 deletions packages/auth0/test/ci-smoke.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
const AUTH0_URL = `https://localhost:${AUTH0_PORT}`;

// Ensure built distribution is present; if not, build it so the smoke test can run locally
if (!existsSync("./dist/index.cjs")) {
if (!existsSync("./dist/index.mjs")) {
console.log("ci-smoke: dist not found, running `pnpm run build`...");
execSync("pnpm run prepack", { stdio: "inherit" });
}

// Helper to start the built auth0 service with a wellness check (reused by tests)
function startAuth0() {
return useService("auth0", "node ./bin/start.cjs", {
return useService("auth0", "node ./bin/start.mjs", {
wellnessCheck: {
timeout: 30000,
*operation(_stdio) {
Expand Down
14 changes: 7 additions & 7 deletions packages/auth0/tsdown.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ import { defineConfig } from "tsdown";
export default defineConfig({
name: "auth0",
entry: "./src/index.ts",
exports: { devExports: "development" },
format: ["esm", "cjs"],
dts: {
sourcemap: true,
deps: {
// if we unbundle, we want to skip this as well
skipNodeModulesBundle: true,
},
exports: { devExports: "development" },
format: ["esm"],
copy: [{ from: "src/views/public", to: "dist", flatten: false }],
// not really required and can mangle things
minify: false,
// don't bundle up as have some relative path imports for static assets
unbundle: true,
// if we unbundle, we want to skip this as well
skipNodeModulesBundle: true,
unused: true,
// runs with @arethetypeswrong/core which checks types
attw: true,
attw: { profile: "esm-only" },
publint: true,
});
13 changes: 3 additions & 10 deletions packages/foundation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
"src"
],
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.cts",
"typesVersions": {
"*": {
Expand All @@ -39,17 +37,13 @@
"exports": {
".": {
"development": "./src/index.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
"default": "./dist/index.mjs"
},
"./package.json": "./package.json"
},
"publishConfig": {
"exports": {
".": {
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
},
".": "./dist/index.mjs",
"./package.json": "./package.json"
}
},
Expand All @@ -75,8 +69,7 @@
"express": "^5.2.1",
"fdir": "^6.5.0",
"http-proxy-middleware": "^3.0.5",
"lodash": "^4.17.23",
"openapi-backend": "^5.16.1",
"openapi-backend": "^5.17.0",
"starfx": "0.16.0"
},
"devDependencies": {
Expand Down
14 changes: 9 additions & 5 deletions packages/foundation/tsdown.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ import { defineConfig } from "tsdown";
export default defineConfig({
name: "foundation",
entry: "./src/index.ts",
exports: { devExports: "development" },
format: ["esm", "cjs"],
dts: {
sourcemap: true,
deps: {
// if we unbundle, we want to skip this as well
skipNodeModulesBundle: true,
},
exports: { devExports: "development" },
format: ["esm"],
minify: false,
// don't bundle up as have some relative path imports for static assets
unbundle: true,
unused: true,
// runs with @arethetypeswrong/core which checks types
attw: true,
attw: { profile: "esm-only" },
publint: true,
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node
const githubAPIsimulator = require("../dist/index.cjs");
import { simulation } from "../dist/index.mjs";

const app = githubAPIsimulator.simulation();
const app = simulation();
app.listen(3300, () =>
console.log(`github-api simulation server started at http://localhost:3300`),
);
12 changes: 3 additions & 9 deletions packages/github-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"url": "git+https://github.com/thefrontside/simulacrum.git",
"directory": "packages/github-api"
},
"bin": "bin/start.cjs",
"bin": "bin/start.mjs",
"files": [
"README.md",
"dist",
Expand All @@ -28,8 +28,6 @@
"repository-mock-data"
],
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.cts",
"typesVersions": {
"*": {
Expand All @@ -42,17 +40,13 @@
"exports": {
".": {
"development": "./src/index.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
"default": "./dist/index.mjs"
},
"./package.json": "./package.json"
},
"publishConfig": {
"exports": {
".": {
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
},
".": "./dist/index.mjs",
"./package.json": "./package.json"
}
},
Expand Down
16 changes: 9 additions & 7 deletions packages/github-api/tsdown.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ import { defineConfig } from "tsdown";
export default defineConfig({
name: "github-api",
entry: "./src/index.ts",
exports: { devExports: "development" },
format: ["esm", "cjs"],
dts: {
sourcemap: true,
deps: {
// if we unbundle, we want to skip this as well
skipNodeModulesBundle: true,
},
// handles dirname
shims: true,
exports: { devExports: "development" },
format: ["esm"],
minify: false,
unused: true,
// don't bundle up as have some relative path imports for static assets
unbundle: true,
// runs with @arethetypeswrong/core which checks types
attw: true,
attw: { profile: "esm-only" },
publint: true,
});
13 changes: 2 additions & 11 deletions packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
"src"
],
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.cts",
"typesVersions": {
"*": {
Expand All @@ -40,17 +38,13 @@
"exports": {
".": {
"development": "./src/index.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
"default": "./dist/index.mjs"
},
"./package.json": "./package.json"
},
"publishConfig": {
"exports": {
".": {
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
},
".": "./dist/index.mjs",
"./package.json": "./package.json"
}
},
Expand All @@ -75,8 +69,5 @@
"devDependencies": {
"@simulacrum/foundation-simulator": "workspace:^",
"@types/picomatch": "^4.0.3"
},
"inlinedDependencies": {
"starfx": "0.16.0"
}
}
14 changes: 9 additions & 5 deletions packages/server/tsdown.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ import { defineConfig } from "tsdown";
export default defineConfig({
name: "server",
entry: "./src/index.ts",
exports: { devExports: "development" },
format: ["esm", "cjs"],
dts: {
sourcemap: true,
deps: {
// if we unbundle, we want to skip this as well
skipNodeModulesBundle: true,
},
exports: { devExports: "development" },
format: ["esm"],
minify: false,
// don't bundle up as have some relative path imports for static assets
unbundle: true,
unused: true,
// runs with @arethetypeswrong/core which checks types
attw: true,
attw: { profile: "esm-only" },
publint: true,
});
Loading
Loading