@williamthorsen/nmr-core 0.5.0 → 0.6.0

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.
package/README.md CHANGED
@@ -5,13 +5,13 @@ Shared utilities for node-monorepo-tools packages.
5
5
  This package serves as the shared library foundation for the monorepo. For the nmr CLI tool, see [`@williamthorsen/nmr`](../nmr).
6
6
 
7
7
  <!-- section:release-notes -->
8
- ## Release notes — v0.5.0 (2026-06-30)
8
+ ## Release notes — v0.6.0 (2026-07-01)
9
9
 
10
10
  ### 🎉 Features
11
11
 
12
- - Reject unexpected positional arguments by default (#432)
12
+ - 🚨 **Breaking:** Rebuild nmr-compile on a unified tsc emit (#455)
13
13
 
14
- Commands built on nmr-core now reject unexpected positional arguments by default. Commands that take positional arguments can opt back in to accept them.
14
+ `nmr` now compiles a package's JavaScript and type declarations in one step, rewriting every import form — static, re-export, dynamic `import()`, bare side-effect, and tsconfig `paths` aliases — to runnable `.js` in both outputs. It now requires TypeScript 5.7 or newer as a peer dependency.
15
15
  <!-- /section:release-notes -->
16
16
 
17
17
  ## Installation
package/dist/esm/.cache CHANGED
@@ -1 +1 @@
1
- 013bcb628c595167bd8f50dc003360ccacb19b7c42d69ce5369dd4f6f7d65d58
1
+ 6527d41fa47a32d6ecdb2ccb3a4414d730a2cd4b9ca6522babe60a12bac7acf1
@@ -1,17 +1,14 @@
1
- import { existsSync } from "node:fs";
2
- import { dirname, resolve } from "node:path";
3
- import { fileURLToPath } from "node:url";
4
- function findPackageRoot(fromUrl) {
5
- let dir = dirname(fileURLToPath(fromUrl));
6
- while (!existsSync(resolve(dir, "package.json"))) {
7
- const parent = dirname(dir);
8
- if (parent === dir) {
9
- throw new Error("Could not find package root from " + fromUrl);
1
+ import { existsSync } from 'node:fs';
2
+ import { dirname, resolve } from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ export function findPackageRoot(fromUrl) {
5
+ let dir = dirname(fileURLToPath(fromUrl));
6
+ while (!existsSync(resolve(dir, 'package.json'))) {
7
+ const parent = dirname(dir);
8
+ if (parent === dir) {
9
+ throw new Error('Could not find package root from ' + fromUrl);
10
+ }
11
+ dir = parent;
10
12
  }
11
- dir = parent;
12
- }
13
- return dir;
13
+ return dir;
14
14
  }
15
- export {
16
- findPackageRoot
17
- };
@@ -1,8 +1,8 @@
1
1
  export declare const PACKAGE_NAME = "@williamthorsen/nmr-core";
2
- export { findPackageRoot } from './findPackageRoot.ts';
3
- export type { FlagDefinition, FlagSchema, ParseArgsOptions, ParsedArgs, ParsedFlags, ParseErrorKind, } from './parseArgs.ts';
4
- export { parseArgs, parseArgsOrExit, ParseError } from './parseArgs.ts';
5
- export { readPackageVersion } from './readPackageVersion.ts';
6
- export { formatErrorLine, printError, printSkip, printStep, printSuccess, reportError, reportWriteResult, } from './terminal.ts';
7
- export type { WriteOutcome, WriteResult } from './writeFileWithCheck.ts';
8
- export { writeFileWithCheck } from './writeFileWithCheck.ts';
2
+ export { findPackageRoot } from './findPackageRoot.js';
3
+ export type { FlagDefinition, FlagSchema, ParseArgsOptions, ParsedArgs, ParsedFlags, ParseErrorKind, } from './parseArgs.js';
4
+ export { parseArgs, parseArgsOrExit, ParseError } from './parseArgs.js';
5
+ export { readPackageVersion } from './readPackageVersion.js';
6
+ export { formatErrorLine, printError, printSkip, printStep, printSuccess, reportError, reportWriteResult, } from './terminal.js';
7
+ export type { WriteOutcome, WriteResult } from './writeFileWithCheck.js';
8
+ export { writeFileWithCheck } from './writeFileWithCheck.js';
package/dist/esm/index.js CHANGED
@@ -1,30 +1,6 @@
1
- const PACKAGE_NAME = "@williamthorsen/nmr-core";
2
- import { findPackageRoot } from "./findPackageRoot.js";
3
- import { parseArgs, parseArgsOrExit, ParseError } from "./parseArgs.js";
4
- import { readPackageVersion } from "./readPackageVersion.js";
5
- import {
6
- formatErrorLine,
7
- printError,
8
- printSkip,
9
- printStep,
10
- printSuccess,
11
- reportError,
12
- reportWriteResult
13
- } from "./terminal.js";
14
- import { writeFileWithCheck } from "./writeFileWithCheck.js";
15
- export {
16
- PACKAGE_NAME,
17
- ParseError,
18
- findPackageRoot,
19
- formatErrorLine,
20
- parseArgs,
21
- parseArgsOrExit,
22
- printError,
23
- printSkip,
24
- printStep,
25
- printSuccess,
26
- readPackageVersion,
27
- reportError,
28
- reportWriteResult,
29
- writeFileWithCheck
30
- };
1
+ export const PACKAGE_NAME = '@williamthorsen/nmr-core';
2
+ export { findPackageRoot } from "./findPackageRoot.js";
3
+ export { parseArgs, parseArgsOrExit, ParseError } from "./parseArgs.js";
4
+ export { readPackageVersion } from "./readPackageVersion.js";
5
+ export { formatErrorLine, printError, printSkip, printStep, printSuccess, reportError, reportWriteResult, } from "./terminal.js";
6
+ export { writeFileWithCheck } from "./writeFileWithCheck.js";
@@ -1,89 +1,86 @@
1
- import process from "node:process";
2
- import { parseArgs as nodeParseArgs } from "node:util";
1
+ import process from 'node:process';
2
+ import { parseArgs as nodeParseArgs } from 'node:util';
3
3
  import { reportError } from "./terminal.js";
4
- class ParseError extends Error {
5
- kind;
6
- flag;
7
- constructor(kind, flag) {
8
- super(formatParseErrorMessage(kind, flag));
9
- this.name = "ParseError";
10
- this.kind = kind;
11
- this.flag = flag;
12
- }
13
- }
14
- function parseArgs(argv, schema, options = {}) {
15
- const nodeOptions = {};
16
- const byName = /* @__PURE__ */ new Map();
17
- const flags = {};
18
- for (const [key, def] of Object.entries(schema)) {
19
- const name = def.long.replace(/^--/, "");
20
- nodeOptions[name] = def.short === void 0 ? { type: def.type } : { type: def.type, short: def.short.replace(/^-/, "") };
21
- byName.set(name, { key, def });
22
- flags[key] = def.type === "boolean" ? false : void 0;
23
- }
24
- const { tokens } = nodeParseArgs({
25
- args: argv,
26
- options: nodeOptions,
27
- strict: false,
28
- allowPositionals: true,
29
- tokens: true
30
- });
31
- const positionals = [];
32
- for (const token of tokens) {
33
- if (token.kind === "positional") {
34
- if (options.allowPositionals !== true) {
35
- throw new ParseError("unexpected-positional", token.value);
36
- }
37
- positionals.push(token.value);
38
- continue;
39
- }
40
- if (token.kind !== "option") {
41
- continue;
42
- }
43
- const entry = byName.get(token.name);
44
- if (entry === void 0) {
45
- throw new ParseError("unknown-flag", token.rawName);
4
+ export class ParseError extends Error {
5
+ kind;
6
+ flag;
7
+ constructor(kind, flag) {
8
+ super(formatParseErrorMessage(kind, flag));
9
+ this.name = 'ParseError';
10
+ this.kind = kind;
11
+ this.flag = flag;
46
12
  }
47
- if (entry.def.type === "boolean") {
48
- if (token.value !== void 0) {
49
- throw new ParseError("unexpected-value", token.rawName);
50
- }
51
- flags[entry.key] = true;
52
- continue;
13
+ }
14
+ export function parseArgs(argv, schema, options = {}) {
15
+ const nodeOptions = {};
16
+ const byName = new Map();
17
+ const flags = {};
18
+ for (const [key, def] of Object.entries(schema)) {
19
+ const name = def.long.replace(/^--/, '');
20
+ nodeOptions[name] =
21
+ def.short === undefined ? { type: def.type } : { type: def.type, short: def.short.replace(/^-/, '') };
22
+ byName.set(name, { key, def });
23
+ flags[key] = def.type === 'boolean' ? false : undefined;
53
24
  }
54
- const value = token.value;
55
- if (value === void 0 || value === "" || !token.inlineValue && value.startsWith("-") && value !== "-") {
56
- throw new ParseError("missing-value", token.rawName);
25
+ const { tokens } = nodeParseArgs({
26
+ args: argv,
27
+ options: nodeOptions,
28
+ strict: false,
29
+ allowPositionals: true,
30
+ tokens: true,
31
+ });
32
+ const positionals = [];
33
+ for (const token of tokens) {
34
+ if (token.kind === 'positional') {
35
+ if (options.allowPositionals !== true) {
36
+ throw new ParseError('unexpected-positional', token.value);
37
+ }
38
+ positionals.push(token.value);
39
+ continue;
40
+ }
41
+ if (token.kind !== 'option') {
42
+ continue;
43
+ }
44
+ const entry = byName.get(token.name);
45
+ if (entry === undefined) {
46
+ throw new ParseError('unknown-flag', token.rawName);
47
+ }
48
+ if (entry.def.type === 'boolean') {
49
+ if (token.value !== undefined) {
50
+ throw new ParseError('unexpected-value', token.rawName);
51
+ }
52
+ flags[entry.key] = true;
53
+ continue;
54
+ }
55
+ const value = token.value;
56
+ if (value === undefined || value === '' || (!token.inlineValue && value.startsWith('-') && value !== '-')) {
57
+ throw new ParseError('missing-value', token.rawName);
58
+ }
59
+ flags[entry.key] = value;
57
60
  }
58
- flags[entry.key] = value;
59
- }
60
- return { flags, positionals };
61
+ return { flags, positionals };
61
62
  }
62
- function parseArgsOrExit(argv, schema, options = {}) {
63
- try {
64
- return parseArgs(argv, schema, options);
65
- } catch (error) {
66
- if (error instanceof ParseError) {
67
- reportError(error.message);
68
- process.exit(1);
63
+ export function parseArgsOrExit(argv, schema, options = {}) {
64
+ try {
65
+ return parseArgs(argv, schema, options);
66
+ }
67
+ catch (error) {
68
+ if (error instanceof ParseError) {
69
+ reportError(error.message);
70
+ process.exit(1);
71
+ }
72
+ throw error;
69
73
  }
70
- throw error;
71
- }
72
74
  }
73
75
  function formatParseErrorMessage(kind, flag) {
74
- switch (kind) {
75
- case "unknown-flag":
76
- return `Unknown option: ${flag}`;
77
- case "missing-value":
78
- return `Missing value for option: ${flag}`;
79
- case "unexpected-value":
80
- return `Option does not accept a value: ${flag}`;
81
- case "unexpected-positional":
82
- return `Unexpected positional argument: ${flag}`;
83
- }
76
+ switch (kind) {
77
+ case 'unknown-flag':
78
+ return `Unknown option: ${flag}`;
79
+ case 'missing-value':
80
+ return `Missing value for option: ${flag}`;
81
+ case 'unexpected-value':
82
+ return `Option does not accept a value: ${flag}`;
83
+ case 'unexpected-positional':
84
+ return `Unexpected positional argument: ${flag}`;
85
+ }
84
86
  }
85
- export {
86
- ParseError,
87
- parseArgs,
88
- parseArgsOrExit
89
- };
@@ -1,15 +1,12 @@
1
- import { readFileSync } from "node:fs";
2
- import { resolve } from "node:path";
1
+ import { readFileSync } from 'node:fs';
2
+ import { resolve } from 'node:path';
3
3
  import { findPackageRoot } from "./findPackageRoot.js";
4
- function readPackageVersion(fromUrl) {
5
- const root = findPackageRoot(fromUrl);
6
- const packageJsonPath = resolve(root, "package.json");
7
- const raw = JSON.parse(readFileSync(packageJsonPath, "utf8"));
8
- if (typeof raw !== "object" || raw === null || !("version" in raw) || typeof raw.version !== "string") {
9
- throw new Error(`No string "version" field in ${packageJsonPath}`);
10
- }
11
- return raw.version;
4
+ export function readPackageVersion(fromUrl) {
5
+ const root = findPackageRoot(fromUrl);
6
+ const packageJsonPath = resolve(root, 'package.json');
7
+ const raw = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
8
+ if (typeof raw !== 'object' || raw === null || !('version' in raw) || typeof raw.version !== 'string') {
9
+ throw new Error(`No string "version" field in ${packageJsonPath}`);
10
+ }
11
+ return raw.version;
12
12
  }
13
- export {
14
- readPackageVersion
15
- };
@@ -1,5 +1,5 @@
1
1
  import type { Writable } from 'node:stream';
2
- import type { WriteResult } from './writeFileWithCheck.ts';
2
+ import type { WriteResult } from './writeFileWithCheck.js';
3
3
  export declare function formatErrorLine(message: string): string;
4
4
  export declare function printError(message: string): void;
5
5
  export declare function printSkip(message: string): void;
@@ -1,66 +1,58 @@
1
- import process from "node:process";
2
- function formatErrorLine(message) {
3
- return `Error: ${message}`;
1
+ import process from 'node:process';
2
+ export function formatErrorLine(message) {
3
+ return `Error: ${message}`;
4
4
  }
5
- function printError(message) {
6
- process.stderr.write(` \u274C ${message}
7
- `);
5
+ export function printError(message) {
6
+ process.stderr.write(` ❌ ${message}\n`);
8
7
  }
9
- function printSkip(message) {
10
- console.info(` \u26A0\uFE0F ${message}`);
8
+ export function printSkip(message) {
9
+ console.info(` ⚠️ ${message}`);
11
10
  }
12
- function printStep(message) {
13
- console.info(`
14
- > ${message}`);
11
+ export function printStep(message) {
12
+ console.info(`\n> ${message}`);
15
13
  }
16
- function printSuccess(message) {
17
- console.info(` \u2705 ${message}`);
14
+ export function printSuccess(message) {
15
+ console.info(` ✅ ${message}`);
18
16
  }
19
- function reportError(message, stream = process.stderr) {
20
- stream.write(`${formatErrorLine(message)}
21
- `);
17
+ export function reportError(message, stream = process.stderr) {
18
+ stream.write(`${formatErrorLine(message)}\n`);
22
19
  }
23
- function reportWriteResult(result, dryRun) {
24
- switch (result.outcome) {
25
- case "created":
26
- if (dryRun) {
27
- printSuccess(`[dry-run] Would create ${result.filePath}`);
28
- } else {
29
- printSuccess(`Created ${result.filePath}`);
30
- }
31
- break;
32
- case "overwritten":
33
- if (dryRun) {
34
- printSuccess(`[dry-run] Would overwrite ${result.filePath}`);
35
- } else {
36
- printSuccess(`Overwrote ${result.filePath}`);
37
- }
38
- break;
39
- case "up-to-date":
40
- printSuccess(`${result.filePath} (up to date)`);
41
- break;
42
- case "skipped":
43
- if (result.error) {
44
- printSkip(`${result.filePath} (could not read for comparison: ${result.error})`);
45
- } else {
46
- printSkip(`${result.filePath} (already exists)`);
47
- }
48
- break;
49
- case "failed":
50
- if (result.error) {
51
- printError(`Failed to write ${result.filePath}: ${result.error}`);
52
- } else {
53
- printError(`Failed to write ${result.filePath}`);
54
- }
55
- break;
56
- }
20
+ export function reportWriteResult(result, dryRun) {
21
+ switch (result.outcome) {
22
+ case 'created':
23
+ if (dryRun) {
24
+ printSuccess(`[dry-run] Would create ${result.filePath}`);
25
+ }
26
+ else {
27
+ printSuccess(`Created ${result.filePath}`);
28
+ }
29
+ break;
30
+ case 'overwritten':
31
+ if (dryRun) {
32
+ printSuccess(`[dry-run] Would overwrite ${result.filePath}`);
33
+ }
34
+ else {
35
+ printSuccess(`Overwrote ${result.filePath}`);
36
+ }
37
+ break;
38
+ case 'up-to-date':
39
+ printSuccess(`${result.filePath} (up to date)`);
40
+ break;
41
+ case 'skipped':
42
+ if (result.error) {
43
+ printSkip(`${result.filePath} (could not read for comparison: ${result.error})`);
44
+ }
45
+ else {
46
+ printSkip(`${result.filePath} (already exists)`);
47
+ }
48
+ break;
49
+ case 'failed':
50
+ if (result.error) {
51
+ printError(`Failed to write ${result.filePath}: ${result.error}`);
52
+ }
53
+ else {
54
+ printError(`Failed to write ${result.filePath}`);
55
+ }
56
+ break;
57
+ }
57
58
  }
58
- export {
59
- formatErrorLine,
60
- printError,
61
- printSkip,
62
- printStep,
63
- printSuccess,
64
- reportError,
65
- reportWriteResult
66
- };
@@ -1,41 +1,45 @@
1
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
2
- import { dirname } from "node:path";
1
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
2
+ import { dirname } from 'node:path';
3
3
  function normalizeTrailingWhitespace(content) {
4
- return content.split("\n").map((line) => line.trimEnd()).join("\n").trimEnd();
4
+ return content
5
+ .split('\n')
6
+ .map((line) => line.trimEnd())
7
+ .join('\n')
8
+ .trimEnd();
5
9
  }
6
- function writeFileWithCheck(filePath, content, options) {
7
- const { dryRun, overwrite } = options;
8
- const fileExists = existsSync(filePath);
9
- if (fileExists && !overwrite) {
10
+ export function writeFileWithCheck(filePath, content, options) {
11
+ const { dryRun, overwrite } = options;
12
+ const fileExists = existsSync(filePath);
13
+ if (fileExists && !overwrite) {
14
+ try {
15
+ const existing = readFileSync(filePath, 'utf8');
16
+ if (normalizeTrailingWhitespace(existing) === normalizeTrailingWhitespace(content)) {
17
+ return { filePath, outcome: 'up-to-date' };
18
+ }
19
+ }
20
+ catch (error) {
21
+ const message = error instanceof Error ? error.message : String(error);
22
+ return { filePath, outcome: 'skipped', error: message };
23
+ }
24
+ return { filePath, outcome: 'skipped' };
25
+ }
26
+ const outcome = fileExists ? 'overwritten' : 'created';
27
+ if (dryRun) {
28
+ return { filePath, outcome };
29
+ }
30
+ try {
31
+ mkdirSync(dirname(filePath), { recursive: true });
32
+ }
33
+ catch (error) {
34
+ const message = error instanceof Error ? error.message : String(error);
35
+ return { filePath, outcome: 'failed', error: message };
36
+ }
10
37
  try {
11
- const existing = readFileSync(filePath, "utf8");
12
- if (normalizeTrailingWhitespace(existing) === normalizeTrailingWhitespace(content)) {
13
- return { filePath, outcome: "up-to-date" };
14
- }
15
- } catch (error) {
16
- const message = error instanceof Error ? error.message : String(error);
17
- return { filePath, outcome: "skipped", error: message };
38
+ writeFileSync(filePath, content, 'utf8');
39
+ }
40
+ catch (error) {
41
+ const message = error instanceof Error ? error.message : String(error);
42
+ return { filePath, outcome: 'failed', error: message };
18
43
  }
19
- return { filePath, outcome: "skipped" };
20
- }
21
- const outcome = fileExists ? "overwritten" : "created";
22
- if (dryRun) {
23
44
  return { filePath, outcome };
24
- }
25
- try {
26
- mkdirSync(dirname(filePath), { recursive: true });
27
- } catch (error) {
28
- const message = error instanceof Error ? error.message : String(error);
29
- return { filePath, outcome: "failed", error: message };
30
- }
31
- try {
32
- writeFileSync(filePath, content, "utf8");
33
- } catch (error) {
34
- const message = error instanceof Error ? error.message : String(error);
35
- return { filePath, outcome: "failed", error: message };
36
- }
37
- return { filePath, outcome };
38
45
  }
39
- export {
40
- writeFileWithCheck
41
- };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@williamthorsen/nmr-core",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "private": false,
5
5
  "description": "Shared utilities for node-monorepo-tools packages",
6
6
  "keywords": [