nomen-lang 0.0.2 → 0.0.4
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/dist/index.mjs +21 -4
- package/package.json +1 -1
- package/src/index.ts +45 -6
package/dist/index.mjs
CHANGED
|
@@ -21466,11 +21466,9 @@ const options = yargs(hideBin(process.argv)).usage("Usage: nomen --in [file/fold
|
|
|
21466
21466
|
}).option("audit-runtime", {
|
|
21467
21467
|
describe: "Path to audit_runtime.c, linked in when --audit is set",
|
|
21468
21468
|
type: "string"
|
|
21469
|
-
}).help(true).
|
|
21470
|
-
if (!argv._.length && !argv.in) throw new Error("Missing required argument: in");
|
|
21471
|
-
return true;
|
|
21472
|
-
}).parseSync();
|
|
21469
|
+
}).help(true).parseSync();
|
|
21473
21470
|
try {
|
|
21471
|
+
options.in = options.in ?? resolve_input();
|
|
21474
21472
|
if (!options.in) process.exit(0);
|
|
21475
21473
|
if (fs.existsSync(options.in)) {
|
|
21476
21474
|
let config = {
|
|
@@ -21495,6 +21493,25 @@ try {
|
|
|
21495
21493
|
} catch (err) {
|
|
21496
21494
|
console.log("UH", err);
|
|
21497
21495
|
}
|
|
21496
|
+
function resolve_input() {
|
|
21497
|
+
const cwd = process.cwd();
|
|
21498
|
+
const config_path = path.join(cwd, "package.jsonc");
|
|
21499
|
+
if (fs.existsSync(config_path)) try {
|
|
21500
|
+
const json = fs.readFileSync(config_path, "utf8").replace(/\/\/.*$/gm, "").replace(/\/\*[\s\S]*?\*\//g, "");
|
|
21501
|
+
const parsed = JSON.parse(json);
|
|
21502
|
+
if (parsed.entry) return path.resolve(cwd, parsed.entry);
|
|
21503
|
+
} catch {}
|
|
21504
|
+
let nm_files = [];
|
|
21505
|
+
try {
|
|
21506
|
+
nm_files = fs.readdirSync(cwd).filter((f) => f.endsWith(".nm"));
|
|
21507
|
+
} catch {}
|
|
21508
|
+
if (nm_files.length === 1) return path.resolve(cwd, nm_files[0]);
|
|
21509
|
+
if (nm_files.length > 1) {
|
|
21510
|
+
console.log(`Found ${nm_files.length} .nm files in ${cwd}. Specify which to run with --in:\n ` + nm_files.join("\n "));
|
|
21511
|
+
return;
|
|
21512
|
+
}
|
|
21513
|
+
console.log("Nothing to compile. Pass --in <file/folder>, or run inside a folder with a package.jsonc or a .nm file.");
|
|
21514
|
+
}
|
|
21498
21515
|
function resolve_lib(file_path) {
|
|
21499
21516
|
let dir = path.dirname(path.resolve(file_path));
|
|
21500
21517
|
for (let i = 0; i < 20; i++) {
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -65,15 +65,12 @@ const options = yargs(hideBin(process.argv))
|
|
|
65
65
|
type: "string",
|
|
66
66
|
})
|
|
67
67
|
.help(true)
|
|
68
|
-
.check((argv) => {
|
|
69
|
-
if (!argv._.length && !argv.in) {
|
|
70
|
-
throw new Error("Missing required argument: in");
|
|
71
|
-
}
|
|
72
|
-
return true;
|
|
73
|
-
})
|
|
74
68
|
.parseSync();
|
|
75
69
|
|
|
76
70
|
try {
|
|
71
|
+
// An explicit --in wins; otherwise discover what to compile from the
|
|
72
|
+
// working folder — a package.jsonc `entry`, or a lone .nm file.
|
|
73
|
+
options.in = options.in ?? resolve_input();
|
|
77
74
|
if (!options.in) {
|
|
78
75
|
process.exit(0);
|
|
79
76
|
}
|
|
@@ -123,6 +120,48 @@ try {
|
|
|
123
120
|
console.log("UH", err);
|
|
124
121
|
}
|
|
125
122
|
|
|
123
|
+
function resolve_input(): string | undefined {
|
|
124
|
+
const cwd = process.cwd();
|
|
125
|
+
|
|
126
|
+
// a) A package.jsonc with an `entry` field (the project's main file).
|
|
127
|
+
const config_path = path.join(cwd, "package.jsonc");
|
|
128
|
+
if (fs.existsSync(config_path)) {
|
|
129
|
+
try {
|
|
130
|
+
const raw = fs.readFileSync(config_path, "utf8");
|
|
131
|
+
const json = raw.replace(/\/\/.*$/gm, "").replace(/\/\*[\s\S]*?\*\//g, "");
|
|
132
|
+
const parsed = JSON.parse(json);
|
|
133
|
+
if (parsed.entry) {
|
|
134
|
+
return path.resolve(cwd, parsed.entry);
|
|
135
|
+
}
|
|
136
|
+
} catch {
|
|
137
|
+
// ignore malformed package.jsonc and fall through
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// b) A single .nm file directly in the working folder.
|
|
142
|
+
let nm_files: string[] = [];
|
|
143
|
+
try {
|
|
144
|
+
nm_files = fs.readdirSync(cwd).filter((f) => f.endsWith(".nm"));
|
|
145
|
+
} catch {
|
|
146
|
+
// unreadable working folder
|
|
147
|
+
}
|
|
148
|
+
if (nm_files.length === 1) {
|
|
149
|
+
return path.resolve(cwd, nm_files[0]);
|
|
150
|
+
}
|
|
151
|
+
if (nm_files.length > 1) {
|
|
152
|
+
console.log(
|
|
153
|
+
`Found ${nm_files.length} .nm files in ${cwd}. Specify which to run with --in:\n ` +
|
|
154
|
+
nm_files.join("\n "),
|
|
155
|
+
);
|
|
156
|
+
return undefined;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
console.log(
|
|
160
|
+
"Nothing to compile. Pass --in <file/folder>, or run inside a folder with a package.jsonc or a .nm file.",
|
|
161
|
+
);
|
|
162
|
+
return undefined;
|
|
163
|
+
}
|
|
164
|
+
|
|
126
165
|
function resolve_lib(file_path: string): string | undefined {
|
|
127
166
|
let dir = path.dirname(path.resolve(file_path));
|
|
128
167
|
for (let i = 0; i < 20; i++) {
|