@adamhl8/configs 3.5.0 → 3.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -35,12 +35,17 @@ const instrumenter = createInstrumenter({
35
35
  coverageVariable: INSTRUMENTER_COVERAGE_VARIABLE
36
36
  });
37
37
  const installedDist = new RegExp(String.raw`^(.*/node_modules/${RegExp.escape(packageName)})/dist/.*\.js$`, "v");
38
+ const sourceMappingUrl = /^\/\/# sourceMappingURL=/mv;
38
39
  bun.plugin({
39
40
  name: "subprocess-coverage",
40
41
  setup: (build) => {
41
42
  build.onLoad({ filter: installedDist }, async ({ path: file }) => {
42
43
  const [, packageDir = ""] = installedDist.exec(file) ?? [];
43
44
  const code = await bun.file(file).text();
45
+ if (!sourceMappingUrl.test(code)) return {
46
+ contents: code,
47
+ loader: "js"
48
+ };
44
49
  const sourceMap = await readSourceMap(file, packageDir, root);
45
50
  return {
46
51
  contents: instrumenter.instrumentSync(code, file, sourceMap),
@@ -1 +1 @@
1
- {"version":3,"file":"child-preload.js","names":[],"sources":["../../../src/test-utils/subprocess-coverage/child-preload.ts"],"sourcesContent":["// Records coverage of the installed package in every Bun process that a test starts.\n// Tests load this file through `BUN_OPTIONS` once a project imports `subprocess-coverage`.\nimport crypto from \"node:crypto\"\nimport fs from \"node:fs\"\nimport path from \"node:path\"\n\nimport { createInstrumenter } from \"@vitest/istanbul-lib-instrument\"\nimport type { InputSourceMap } from \"@vitest/istanbul-lib-instrument\"\nimport bun from \"bun\"\n\nimport { SUBPROCESS_COVERAGE_SETTINGS_VAR } from \"#test-utils/subprocess-coverage/env.ts\"\nimport type { CoverageSettings } from \"#test-utils/subprocess-coverage/env.ts\"\n\nconst INSTRUMENTER_COVERAGE_VARIABLE = \"subprocessCoverage\"\n\nconst isCoverageSettings = (value: unknown): value is CoverageSettings =>\n typeof value === \"object\"\n && value !== null\n && \"rawDir\" in value\n && typeof value.rawDir === \"string\"\n && \"root\" in value\n && typeof value.root === \"string\"\n && \"packageName\" in value\n && typeof value.packageName === \"string\"\n\n/** Reads the coverage settings from the environment, and throws when they're missing or invalid. */\nconst readCoverageSettings = () => {\n const settings = process.env[SUBPROCESS_COVERAGE_SETTINGS_VAR]\n if (settings === undefined)\n throw new Error(`the subprocess coverage preload loaded without ${SUBPROCESS_COVERAGE_SETTINGS_VAR}`)\n const parsed: unknown = JSON.parse(settings)\n if (!isCoverageSettings(parsed)) throw new Error(`${SUBPROCESS_COVERAGE_SETTINGS_VAR} isn't valid: ${settings}`)\n return parsed\n}\n\nconst { rawDir, root, packageName } = readCoverageSettings()\n\nconst isSourceMap = (value: unknown): value is InputSourceMap =>\n typeof value === \"object\" && value !== null && \"sources\" in value && Array.isArray(value.sources)\n\n/** Points each source in the installed package's map at the same file in the project, so reports name `src/`. */\nconst readSourceMap = async (file: string, packageDir: string, projectDir: string) => {\n const sourceMap: unknown = await bun.file(`${file}.map`).json()\n if (!isSourceMap(sourceMap)) throw new Error(`no source map for ${file}`)\n const sources = sourceMap.sources.map((source) => {\n const installedSource = path.resolve(path.dirname(file), source ?? \"\")\n return path.join(projectDir, path.relative(packageDir, installedSource))\n })\n return { ...sourceMap, sources }\n}\n\nconst instrumenter = createInstrumenter({ esModules: true, coverageVariable: INSTRUMENTER_COVERAGE_VARIABLE })\n// Match the built files of the copy that a test project installs, and capture its package dir.\nconst installedDist = new RegExp(String.raw`^(.*/node_modules/${RegExp.escape(packageName)})/dist/.*\\.js$`, \"v\")\n\nbun.plugin({\n name: \"subprocess-coverage\",\n setup: (build) => {\n build.onLoad({ filter: installedDist }, async ({ path: file }) => {\n const [, packageDir = \"\"] = installedDist.exec(file) ?? []\n const code = await bun.file(file).text()\n const sourceMap = await readSourceMap(file, packageDir, root)\n return { contents: instrumenter.instrumentSync(code, file, sourceMap), loader: \"js\" }\n })\n },\n})\n\nconst hasCoverage = (value: object): value is Record<typeof INSTRUMENTER_COVERAGE_VARIABLE, unknown> =>\n INSTRUMENTER_COVERAGE_VARIABLE in value\n\nconst writeCoverage = () => {\n // Copy `globalThis` to a local because TypeScript doesn't narrow `globalThis` itself.\n const globalScope: object = globalThis\n // Skip a process that never loaded the package, because only instrumented code creates the global.\n if (!hasCoverage(globalScope)) return\n fs.writeFileSync(\n path.join(rawDir, `${crypto.randomUUID()}.json`),\n JSON.stringify(globalScope[INSTRUMENTER_COVERAGE_VARIABLE]),\n )\n}\n\nprocess.on(\"exit\", writeCoverage)\n\n// Move `writeCoverage` behind each later exit listener so the coverage file includes what those listeners run.\n// Wait a microtask because `newListener` fires before the new listener is added.\n// A listener added in the same tick as a synchronous `process.exit()` still runs after the write.\nprocess.on(\"newListener\", (event, listener) => {\n if (event !== \"exit\" || listener === writeCoverage) return\n queueMicrotask(() => {\n process.removeListener(\"exit\", writeCoverage)\n process.on(\"exit\", writeCoverage)\n })\n})\n"],"mappings":";;;;;;;AAaA,MAAM,iCAAiC;AAEvC,MAAM,sBAAsB,UAC1B,OAAO,UAAU,YACd,UAAU,QACV,YAAY,SACZ,OAAO,MAAM,WAAW,YACxB,UAAU,SACV,OAAO,MAAM,SAAS,YACtB,iBAAiB,SACjB,OAAO,MAAM,gBAAgB;;AAGlC,MAAM,6BAA6B;CACjC,MAAM,WAAW,QAAQ,IAAI;CAC7B,IAAI,aAAa,KAAA,GACf,MAAM,IAAI,MAAM,kDAAkD,kCAAkC;CACtG,MAAM,SAAkB,KAAK,MAAM,QAAQ;CAC3C,IAAI,CAAC,mBAAmB,MAAM,GAAG,MAAM,IAAI,MAAM,GAAG,iCAAiC,gBAAgB,UAAU;CAC/G,OAAO;AACT;AAEA,MAAM,EAAE,QAAQ,MAAM,gBAAgB,qBAAqB;AAE3D,MAAM,eAAe,UACnB,OAAO,UAAU,YAAY,UAAU,QAAQ,aAAa,SAAS,MAAM,QAAQ,MAAM,OAAO;;AAGlG,MAAM,gBAAgB,OAAO,MAAc,YAAoB,eAAuB;CACpF,MAAM,YAAqB,MAAM,IAAI,KAAK,GAAG,KAAK,KA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,QAAQ,aAAa;EAC5C,QAAQ,GAAG,QAAQ,aAAa;CAClC,CAAC;AACH,CAAC"}
1
+ {"version":3,"file":"child-preload.js","names":[],"sources":["../../../src/test-utils/subprocess-coverage/child-preload.ts"],"sourcesContent":["// Records coverage of the installed package in every Bun process that a test starts.\n// Tests load this file through `BUN_OPTIONS` once a project imports `subprocess-coverage`.\nimport crypto from \"node:crypto\"\nimport fs from \"node:fs\"\nimport path from \"node:path\"\n\nimport { createInstrumenter } from \"@vitest/istanbul-lib-instrument\"\nimport type { InputSourceMap } from \"@vitest/istanbul-lib-instrument\"\nimport bun from \"bun\"\n\nimport { SUBPROCESS_COVERAGE_SETTINGS_VAR } from \"#test-utils/subprocess-coverage/env.ts\"\nimport type { CoverageSettings } from \"#test-utils/subprocess-coverage/env.ts\"\n\nconst INSTRUMENTER_COVERAGE_VARIABLE = \"subprocessCoverage\"\n\nconst isCoverageSettings = (value: unknown): value is CoverageSettings =>\n typeof value === \"object\"\n && value !== null\n && \"rawDir\" in value\n && typeof value.rawDir === \"string\"\n && \"root\" in value\n && typeof value.root === \"string\"\n && \"packageName\" in value\n && typeof value.packageName === \"string\"\n\n/** Reads the coverage settings from the environment, and throws when they're missing or invalid. */\nconst readCoverageSettings = () => {\n const settings = process.env[SUBPROCESS_COVERAGE_SETTINGS_VAR]\n if (settings === undefined)\n throw new Error(`the subprocess coverage preload loaded without ${SUBPROCESS_COVERAGE_SETTINGS_VAR}`)\n const parsed: unknown = JSON.parse(settings)\n if (!isCoverageSettings(parsed)) throw new Error(`${SUBPROCESS_COVERAGE_SETTINGS_VAR} isn't valid: ${settings}`)\n return parsed\n}\n\nconst { rawDir, root, packageName } = readCoverageSettings()\n\nconst isSourceMap = (value: unknown): value is InputSourceMap =>\n typeof value === \"object\" && value !== null && \"sources\" in value && Array.isArray(value.sources)\n\n/** Points each source in the installed package's map at the same file in the project, so reports name `src/`. */\nconst readSourceMap = async (file: string, packageDir: string, projectDir: string) => {\n const sourceMap: unknown = await bun.file(`${file}.map`).json()\n if (!isSourceMap(sourceMap)) throw new Error(`no source map for ${file}`)\n const sources = sourceMap.sources.map((source) => {\n const installedSource = path.resolve(path.dirname(file), source ?? \"\")\n return path.join(projectDir, path.relative(packageDir, installedSource))\n })\n return { ...sourceMap, sources }\n}\n\nconst instrumenter = createInstrumenter({ esModules: true, coverageVariable: INSTRUMENTER_COVERAGE_VARIABLE })\n// Match the built files of the copy that a test project installs, and capture its package dir.\nconst installedDist = new RegExp(String.raw`^(.*/node_modules/${RegExp.escape(packageName)})/dist/.*\\.js$`, \"v\")\n// Match the comment that a bundler adds to each file it writes a source map for.\nconst sourceMappingUrl = /^\\/\\/# sourceMappingURL=/mv\n\nbun.plugin({\n name: \"subprocess-coverage\",\n setup: (build) => {\n build.onLoad({ filter: installedDist }, async ({ path: file }) => {\n const [, packageDir = \"\"] = installedDist.exec(file) ?? []\n const code = await bun.file(file).text()\n // Pass through a file with no map, like a re-export-only entry, because it has no source of its own to cover.\n // A file whose comment names a missing map still throws, so a broken build doesn't go unnoticed.\n if (!sourceMappingUrl.test(code)) return { contents: code, loader: \"js\" }\n const sourceMap = await readSourceMap(file, packageDir, root)\n return { contents: instrumenter.instrumentSync(code, file, sourceMap), loader: \"js\" }\n })\n },\n})\n\nconst hasCoverage = (value: object): value is Record<typeof INSTRUMENTER_COVERAGE_VARIABLE, unknown> =>\n INSTRUMENTER_COVERAGE_VARIABLE in value\n\nconst writeCoverage = () => {\n // Copy `globalThis` to a local because TypeScript doesn't narrow `globalThis` itself.\n const globalScope: object = globalThis\n // Skip a process that never loaded the package, because only instrumented code creates the global.\n if (!hasCoverage(globalScope)) return\n fs.writeFileSync(\n path.join(rawDir, `${crypto.randomUUID()}.json`),\n JSON.stringify(globalScope[INSTRUMENTER_COVERAGE_VARIABLE]),\n )\n}\n\nprocess.on(\"exit\", writeCoverage)\n\n// Move `writeCoverage` behind each later exit listener so the coverage file includes what those listeners run.\n// Wait a microtask because `newListener` fires before the new listener is added.\n// A listener added in the same tick as a synchronous `process.exit()` still runs after the write.\nprocess.on(\"newListener\", (event, listener) => {\n if (event !== \"exit\" || listener === writeCoverage) return\n queueMicrotask(() => {\n process.removeListener(\"exit\", writeCoverage)\n process.on(\"exit\", writeCoverage)\n })\n})\n"],"mappings":";;;;;;;AAaA,MAAM,iCAAiC;AAEvC,MAAM,sBAAsB,UAC1B,OAAO,UAAU,YACd,UAAU,QACV,YAAY,SACZ,OAAO,MAAM,WAAW,YACxB,UAAU,SACV,OAAO,MAAM,SAAS,YACtB,iBAAiB,SACjB,OAAO,MAAM,gBAAgB;;AAGlC,MAAM,6BAA6B;CACjC,MAAM,WAAW,QAAQ,IAAI;CAC7B,IAAI,aAAa,KAAA,GACf,MAAM,IAAI,MAAM,kDAAkD,kCAAkC;CACtG,MAAM,SAAkB,KAAK,MAAM,QAAQ;CAC3C,IAAI,CAAC,mBAAmB,MAAM,GAAG,MAAM,IAAI,MAAM,GAAG,iCAAiC,gBAAgB,UAAU;CAC/G,OAAO;AACT;AAEA,MAAM,EAAE,QAAQ,MAAM,gBAAgB,qBAAqB;AAE3D,MAAM,eAAe,UACnB,OAAO,UAAU,YAAY,UAAU,QAAQ,aAAa,SAAS,MAAM,QAAQ,MAAM,OAAO;;AAGlG,MAAM,gBAAgB,OAAO,MAAc,YAAoB,eAAuB;CACpF,MAAM,YAAqB,MAAM,IAAI,KAAK,GAAG,KAAK,KAAK,CAAC,CAAC,KAAK;CAC9D,IAAI,CAAC,YAAY,SAAS,GAAG,MAAM,IAAI,MAAM,qBAAqB,MAAM;CACxE,MAAM,UAAU,UAAU,QAAQ,KAAK,WAAW;EAChD,MAAM,kBAAkB,KAAK,QAAQ,KAAK,QAAQ,IAAI,GAAG,UAAU,EAAE;EACrE,OAAO,KAAK,KAAK,YAAY,KAAK,SAAS,YAAY,eAAe,CAAC;CACzE,CAAC;CACD,OAAO;EAAE,GAAG;EAAW;CAAQ;AACjC;AAEA,MAAM,eAAe,mBAAmB;CAAE,WAAW;CAAM,kBAAkB;AAA+B,CAAC;AAE7G,MAAM,gBAAgB,IAAI,OAAO,OAAO,GAAG,qBAAqB,OAAO,OAAO,WAAW,EAAE,iBAAiB,GAAG;AAE/G,MAAM,mBAAmB;AAEzB,IAAI,OAAO;CACT,MAAM;CACN,QAAQ,UAAU;EAChB,MAAM,OAAO,EAAE,QAAQ,cAAc,GAAG,OAAO,EAAE,MAAM,WAAW;GAChE,MAAM,GAAG,aAAa,MAAM,cAAc,KAAK,IAAI,KAAK,CAAC;GACzD,MAAM,OAAO,MAAM,IAAI,KAAK,IAAI,CAAC,CAAC,KAAK;GAGvC,IAAI,CAAC,iBAAiB,KAAK,IAAI,GAAG,OAAO;IAAE,UAAU;IAAM,QAAQ;GAAK;GACxE,MAAM,YAAY,MAAM,cAAc,MAAM,YAAY,IAAI;GAC5D,OAAO;IAAE,UAAU,aAAa,eAAe,MAAM,MAAM,SAAS;IAAG,QAAQ;GAAK;EACtF,CAAC;CACH;AACF,CAAC;AAED,MAAM,eAAe,UACnB,kCAAkC;AAEpC,MAAM,sBAAsB;CAE1B,MAAM,cAAsB;CAE5B,IAAI,CAAC,YAAY,WAAW,GAAG;CAC/B,GAAG,cACD,KAAK,KAAK,QAAQ,GAAG,OAAO,WAAW,EAAE,MAAM,GAC/C,KAAK,UAAU,YAAY,+BAA+B,CAC5D;AACF;AAEA,QAAQ,GAAG,QAAQ,aAAa;AAKhC,QAAQ,GAAG,gBAAgB,OAAO,aAAa;CAC7C,IAAI,UAAU,UAAU,aAAa,eAAe;CACpD,qBAAqB;EACnB,QAAQ,eAAe,QAAQ,aAAa;EAC5C,QAAQ,GAAG,QAAQ,aAAa;CAClC,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adamhl8/configs",
3
- "version": "3.5.0",
3
+ "version": "3.5.1",
4
4
  "description": "My shared configs for TS projects",
5
5
  "homepage": "https://github.com/adamhl8/configs",
6
6
  "bugs": {