thinkwell 0.5.5 → 0.5.6
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/agent.d.ts.map +1 -1
- package/dist/agent.js +207 -279
- package/dist/agent.js.map +1 -1
- package/dist/build.js +44 -98
- package/dist/cli/build.js +92 -227
- package/dist/cli/bundle.js +570 -1136
- package/dist/cli/check.js +125 -214
- package/dist/cli/commands.js +63 -177
- package/dist/cli/compiler-host.js +81 -190
- package/dist/cli/dependency-check.js +125 -269
- package/dist/cli/dependency-errors.js +12 -84
- package/dist/cli/fmt.js +1 -13
- package/dist/cli/init-command.js +21 -68
- package/dist/cli/init.js +90 -220
- package/dist/cli/loader.js +95 -361
- package/dist/cli/new-command.js +25 -73
- package/dist/cli/package-manager.js +50 -117
- package/dist/cli/schema.js +89 -245
- package/dist/cli/workspace.js +92 -226
- package/dist/connectors/index.js +1 -7
- package/dist/generated/features.d.ts +5 -0
- package/dist/generated/features.d.ts.map +1 -0
- package/dist/generated/features.js +4 -0
- package/dist/generated/features.js.map +1 -0
- package/dist/index.js +0 -5
- package/dist/schema.js +3 -36
- package/dist/session.js +50 -82
- package/dist/think-builder.d.ts.map +1 -1
- package/dist/think-builder.js +269 -370
- package/dist/think-builder.js.map +1 -1
- package/dist/thought-event.d.ts +1 -0
- package/dist/thought-event.d.ts.map +1 -1
- package/dist/thought-event.js +0 -1
- package/dist/thought-stream.js +60 -96
- package/dist-pkg/acp.cjs +13385 -1876
- package/dist-pkg/cli-build.cjs +171 -369
- package/dist-pkg/cli-bundle.cjs +289 -690
- package/dist-pkg/cli-check.cjs +202 -415
- package/dist-pkg/cli-dependency-check.cjs +39 -82
- package/dist-pkg/cli-dependency-errors.cjs +9 -41
- package/dist-pkg/cli-loader.cjs +90 -173
- package/dist-pkg/protocol.cjs +2 -8
- package/dist-pkg/thinkwell.cjs +876 -1842
- package/package.json +7 -6
package/dist-pkg/cli-bundle.cjs
CHANGED
|
@@ -240881,61 +240881,49 @@ var import_node_fs = require("node:fs");
|
|
|
240881
240881
|
var import_ts_json_schema_generator = __toESM(require_dist(), 1);
|
|
240882
240882
|
function findTsConfig(startDir) {
|
|
240883
240883
|
let dir = startDir;
|
|
240884
|
-
|
|
240884
|
+
for (; ; ) {
|
|
240885
240885
|
const configPath = (0, import_node_path.join)(dir, "tsconfig.json");
|
|
240886
|
-
if ((0, import_node_fs.existsSync)(configPath))
|
|
240886
|
+
if ((0, import_node_fs.existsSync)(configPath))
|
|
240887
240887
|
return configPath;
|
|
240888
|
-
}
|
|
240889
240888
|
const parent = (0, import_node_path.dirname)(dir);
|
|
240890
|
-
if (parent === dir)
|
|
240891
|
-
return
|
|
240892
|
-
}
|
|
240889
|
+
if (parent === dir)
|
|
240890
|
+
return;
|
|
240893
240891
|
dir = parent;
|
|
240894
240892
|
}
|
|
240895
240893
|
}
|
|
240896
240894
|
__name(findTsConfig, "findTsConfig");
|
|
240897
240895
|
function inlineRefs(obj, definitions) {
|
|
240898
|
-
if (obj === null || typeof obj
|
|
240896
|
+
if (obj === null || typeof obj != "object")
|
|
240899
240897
|
return obj;
|
|
240900
|
-
|
|
240901
|
-
if (Array.isArray(obj)) {
|
|
240898
|
+
if (Array.isArray(obj))
|
|
240902
240899
|
return obj.map((item) => inlineRefs(item, definitions));
|
|
240903
|
-
}
|
|
240904
240900
|
const record = obj;
|
|
240905
|
-
if (typeof record
|
|
240906
|
-
const
|
|
240907
|
-
|
|
240908
|
-
if (match && definitions[match[1]]) {
|
|
240901
|
+
if (typeof record.$ref == "string") {
|
|
240902
|
+
const match = record.$ref.match(/^#\/definitions\/(.+)$/);
|
|
240903
|
+
if (match && definitions[match[1]])
|
|
240909
240904
|
return inlineRefs(definitions[match[1]], definitions);
|
|
240910
|
-
}
|
|
240911
240905
|
}
|
|
240912
240906
|
const result = {};
|
|
240913
|
-
for (const [key2, value] of Object.entries(record))
|
|
240907
|
+
for (const [key2, value] of Object.entries(record))
|
|
240914
240908
|
result[key2] = inlineRefs(value, definitions);
|
|
240915
|
-
}
|
|
240916
240909
|
return result;
|
|
240917
240910
|
}
|
|
240918
240911
|
__name(inlineRefs, "inlineRefs");
|
|
240919
240912
|
function cleanSchema(typeName, schema) {
|
|
240920
240913
|
const definitions = schema.definitions || {};
|
|
240921
240914
|
let result = definitions[typeName] || schema;
|
|
240922
|
-
result = inlineRefs(result, definitions)
|
|
240923
|
-
if (typeof result === "object" && result !== null) {
|
|
240915
|
+
if (result = inlineRefs(result, definitions), typeof result == "object" && result !== null) {
|
|
240924
240916
|
const cleaned = { ...result };
|
|
240925
|
-
delete cleaned
|
|
240926
|
-
delete cleaned["definitions"];
|
|
240927
|
-
return cleaned;
|
|
240917
|
+
return delete cleaned.$schema, delete cleaned.definitions, cleaned;
|
|
240928
240918
|
}
|
|
240929
240919
|
return result;
|
|
240930
240920
|
}
|
|
240931
240921
|
__name(cleanSchema, "cleanSchema");
|
|
240932
240922
|
function generateSchemas(filePath, typeNames) {
|
|
240933
240923
|
const schemas = /* @__PURE__ */ new Map();
|
|
240934
|
-
if (typeNames.length === 0)
|
|
240924
|
+
if (typeNames.length === 0)
|
|
240935
240925
|
return schemas;
|
|
240936
|
-
|
|
240937
|
-
const configPath = findTsConfig((0, import_node_path.dirname)(filePath));
|
|
240938
|
-
const generator = (0, import_ts_json_schema_generator.createGenerator)({
|
|
240926
|
+
const configPath = findTsConfig((0, import_node_path.dirname)(filePath)), generator = (0, import_ts_json_schema_generator.createGenerator)({
|
|
240939
240927
|
path: filePath,
|
|
240940
240928
|
...configPath && { tsconfig: configPath },
|
|
240941
240929
|
skipTypeCheck: true,
|
|
@@ -240952,8 +240940,7 @@ __name(generateSchemas, "generateSchemas");
|
|
|
240952
240940
|
// dist/cli/schema.js
|
|
240953
240941
|
var JSONSCHEMA_TAG = "JSONSchema";
|
|
240954
240942
|
function hasJsDocTag(node, tagName) {
|
|
240955
|
-
|
|
240956
|
-
return jsDocNodes.some((tag) => tag.tagName.text === tagName);
|
|
240943
|
+
return import_typescript.default.getJSDocTags(node).some((tag) => tag.tagName.text === tagName);
|
|
240957
240944
|
}
|
|
240958
240945
|
__name(hasJsDocTag, "hasJsDocTag");
|
|
240959
240946
|
function findMarkedTypes(path, source) {
|
|
@@ -240963,48 +240950,36 @@ function findMarkedTypes(path, source) {
|
|
|
240963
240950
|
import_typescript.default.ScriptTarget.Latest,
|
|
240964
240951
|
true
|
|
240965
240952
|
// setParentNodes - needed for JSDoc traversal
|
|
240966
|
-
);
|
|
240967
|
-
|
|
240968
|
-
|
|
240969
|
-
|
|
240970
|
-
if (
|
|
240971
|
-
const
|
|
240972
|
-
|
|
240973
|
-
|
|
240974
|
-
|
|
240975
|
-
|
|
240976
|
-
|
|
240977
|
-
|
|
240978
|
-
|
|
240979
|
-
|
|
240980
|
-
|
|
240981
|
-
|
|
240982
|
-
|
|
240983
|
-
|
|
240984
|
-
|
|
240985
|
-
node,
|
|
240986
|
-
startPosition: node.getStart(),
|
|
240987
|
-
endPosition: node.getEnd(),
|
|
240988
|
-
line: line + 1,
|
|
240989
|
-
column: character + 1,
|
|
240990
|
-
declarationLength,
|
|
240991
|
-
isExported
|
|
240992
|
-
});
|
|
240993
|
-
}
|
|
240953
|
+
), results = [];
|
|
240954
|
+
return import_typescript.default.forEachChild(sourceFile, /* @__PURE__ */ __name(function visit(node) {
|
|
240955
|
+
if ((import_typescript.default.isInterfaceDeclaration(node) || import_typescript.default.isTypeAliasDeclaration(node) || import_typescript.default.isEnumDeclaration(node) || import_typescript.default.isClassDeclaration(node)) && hasJsDocTag(node, JSONSCHEMA_TAG)) {
|
|
240956
|
+
const name = node.name?.text;
|
|
240957
|
+
if (name) {
|
|
240958
|
+
const { line, character } = sourceFile.getLineAndCharacterOfPosition(node.getStart());
|
|
240959
|
+
let keyword = "interface";
|
|
240960
|
+
import_typescript.default.isTypeAliasDeclaration(node) ? keyword = "type" : import_typescript.default.isEnumDeclaration(node) ? keyword = "enum" : import_typescript.default.isClassDeclaration(node) && (keyword = "class");
|
|
240961
|
+
const declarationLength = keyword.length + 1 + name.length, isExported = node.modifiers?.some((m) => m.kind === import_typescript.default.SyntaxKind.ExportKeyword) ?? false;
|
|
240962
|
+
results.push({
|
|
240963
|
+
name,
|
|
240964
|
+
node,
|
|
240965
|
+
startPosition: node.getStart(),
|
|
240966
|
+
endPosition: node.getEnd(),
|
|
240967
|
+
line: line + 1,
|
|
240968
|
+
column: character + 1,
|
|
240969
|
+
declarationLength,
|
|
240970
|
+
isExported
|
|
240971
|
+
});
|
|
240994
240972
|
}
|
|
240995
240973
|
}
|
|
240996
240974
|
import_typescript.default.forEachChild(node, visit);
|
|
240997
|
-
}, "visit"));
|
|
240998
|
-
return results;
|
|
240975
|
+
}, "visit")), results;
|
|
240999
240976
|
}
|
|
241000
240977
|
__name(findMarkedTypes, "findMarkedTypes");
|
|
241001
240978
|
function resolveGenerateSchemas(projectDir) {
|
|
241002
240979
|
if (projectDir) {
|
|
241003
|
-
const
|
|
241004
|
-
|
|
241005
|
-
if (typeof buildMod.generateSchemas === "function") {
|
|
240980
|
+
const buildMod = (0, import_node_module.createRequire)((0, import_node_path2.join)(projectDir, "package.json"))("thinkwell/build");
|
|
240981
|
+
if (typeof buildMod.generateSchemas == "function")
|
|
241006
240982
|
return buildMod.generateSchemas;
|
|
241007
|
-
}
|
|
241008
240983
|
throw new Error(`thinkwell/build resolved from ${projectDir} but does not export generateSchemas. This may indicate a version mismatch \u2014 try updating the thinkwell dependency.`);
|
|
241009
240984
|
}
|
|
241010
240985
|
return generateSchemas;
|
|
@@ -241012,18 +240987,14 @@ function resolveGenerateSchemas(projectDir) {
|
|
|
241012
240987
|
__name(resolveGenerateSchemas, "resolveGenerateSchemas");
|
|
241013
240988
|
function generateSchemas2(path, types, sourceCode, projectDir) {
|
|
241014
240989
|
const schemas = /* @__PURE__ */ new Map();
|
|
241015
|
-
if (types.length === 0)
|
|
240990
|
+
if (types.length === 0)
|
|
241016
240991
|
return schemas;
|
|
241017
|
-
}
|
|
241018
240992
|
const buildGenerateSchemas = resolveGenerateSchemas(projectDir);
|
|
241019
240993
|
for (const typeInfo of types) {
|
|
241020
240994
|
const { name, line, column } = typeInfo;
|
|
241021
240995
|
try {
|
|
241022
|
-
const
|
|
241023
|
-
|
|
241024
|
-
if (schema) {
|
|
241025
|
-
schemas.set(name, schema);
|
|
241026
|
-
}
|
|
240996
|
+
const schema = buildGenerateSchemas(path, [name]).get(name);
|
|
240997
|
+
schema && schemas.set(name, schema);
|
|
241027
240998
|
} catch (error) {
|
|
241028
240999
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
241029
241000
|
throw new Error(`Failed to generate schema for type '${name}' at ${path}:${line}:${column}
|
|
@@ -241036,27 +241007,27 @@ function generateSchemas2(path, types, sourceCode, projectDir) {
|
|
|
241036
241007
|
__name(generateSchemas2, "generateSchemas");
|
|
241037
241008
|
var ACP_NAMESPACE = "$$__thinkwell__acp__$$";
|
|
241038
241009
|
function generateNamespace(name, schema, isExported) {
|
|
241039
|
-
const schemaJson = JSON.stringify(schema, null, 2).split(
|
|
241040
|
-
|
|
241010
|
+
const schemaJson = JSON.stringify(schema, null, 2).split(`
|
|
241011
|
+
`).map((line, i) => i === 0 ? line : " " + line).join(`
|
|
241012
|
+
`);
|
|
241041
241013
|
return [
|
|
241042
|
-
`${
|
|
241014
|
+
`${isExported ? "export " : ""}namespace ${name} {`,
|
|
241043
241015
|
` export const Schema: ${ACP_NAMESPACE}.SchemaProvider<${name}> = {`,
|
|
241044
241016
|
` toJsonSchema: () => (${schemaJson}) as ${ACP_NAMESPACE}.JsonSchema,`,
|
|
241045
|
-
|
|
241046
|
-
|
|
241047
|
-
].join(
|
|
241017
|
+
" };",
|
|
241018
|
+
"}"
|
|
241019
|
+
].join(`
|
|
241020
|
+
`);
|
|
241048
241021
|
}
|
|
241049
241022
|
__name(generateNamespace, "generateNamespace");
|
|
241050
241023
|
function generateInsertions(types, schemas) {
|
|
241051
241024
|
const insertions = [];
|
|
241052
241025
|
for (const { name, endPosition, isExported } of types) {
|
|
241053
241026
|
const schema = schemas.get(name);
|
|
241054
|
-
|
|
241055
|
-
continue;
|
|
241056
|
-
}
|
|
241057
|
-
insertions.push({
|
|
241027
|
+
schema && insertions.push({
|
|
241058
241028
|
position: endPosition,
|
|
241059
|
-
code:
|
|
241029
|
+
code: `
|
|
241030
|
+
` + generateNamespace(name, schema, isExported)
|
|
241060
241031
|
});
|
|
241061
241032
|
}
|
|
241062
241033
|
return insertions.sort((a, b) => b.position - a.position);
|
|
@@ -241068,9 +241039,8 @@ function generateSchemaImport() {
|
|
|
241068
241039
|
__name(generateSchemaImport, "generateSchemaImport");
|
|
241069
241040
|
function applyInsertions(source, insertions) {
|
|
241070
241041
|
let result = source;
|
|
241071
|
-
for (const { position, code } of insertions)
|
|
241042
|
+
for (const { position, code } of insertions)
|
|
241072
241043
|
result = result.slice(0, position) + code + result.slice(position);
|
|
241073
|
-
}
|
|
241074
241044
|
return result;
|
|
241075
241045
|
}
|
|
241076
241046
|
__name(applyInsertions, "applyInsertions");
|
|
@@ -241079,18 +241049,15 @@ function hasJsonSchemaMarkers(source) {
|
|
|
241079
241049
|
}
|
|
241080
241050
|
__name(hasJsonSchemaMarkers, "hasJsonSchemaMarkers");
|
|
241081
241051
|
function transformJsonSchemas(path, source, projectDir) {
|
|
241082
|
-
if (!hasJsonSchemaMarkers(source))
|
|
241052
|
+
if (!hasJsonSchemaMarkers(source))
|
|
241083
241053
|
return source;
|
|
241084
|
-
}
|
|
241085
241054
|
const markedTypes = findMarkedTypes(path, source);
|
|
241086
|
-
if (markedTypes.length === 0)
|
|
241055
|
+
if (markedTypes.length === 0)
|
|
241087
241056
|
return source;
|
|
241088
|
-
|
|
241089
|
-
const schemas = generateSchemas2(path, markedTypes, source, projectDir);
|
|
241090
|
-
const insertions = generateInsertions(markedTypes, schemas);
|
|
241057
|
+
const schemas = generateSchemas2(path, markedTypes, source, projectDir), insertions = generateInsertions(markedTypes, schemas);
|
|
241091
241058
|
let modifiedSource = applyInsertions(source, insertions);
|
|
241092
|
-
modifiedSource = generateSchemaImport() +
|
|
241093
|
-
|
|
241059
|
+
return modifiedSource = generateSchemaImport() + `
|
|
241060
|
+
` + modifiedSource, modifiedSource;
|
|
241094
241061
|
}
|
|
241095
241062
|
__name(transformJsonSchemas, "transformJsonSchemas");
|
|
241096
241063
|
|
|
@@ -241110,33 +241077,25 @@ var LOCKFILES = [
|
|
|
241110
241077
|
function detectByLockfile(projectDir) {
|
|
241111
241078
|
for (const { file, pm } of LOCKFILES) {
|
|
241112
241079
|
const lockfilePath = (0, import_node_path3.join)(projectDir, file);
|
|
241113
|
-
if ((0, import_node_fs2.existsSync)(lockfilePath))
|
|
241080
|
+
if ((0, import_node_fs2.existsSync)(lockfilePath))
|
|
241114
241081
|
return { pm, lockfile: file };
|
|
241115
|
-
}
|
|
241116
241082
|
}
|
|
241117
241083
|
return null;
|
|
241118
241084
|
}
|
|
241119
241085
|
__name(detectByLockfile, "detectByLockfile");
|
|
241120
241086
|
function parsePackageManagerField(value) {
|
|
241121
|
-
if (typeof value
|
|
241087
|
+
if (typeof value != "string")
|
|
241122
241088
|
return null;
|
|
241123
|
-
|
|
241124
|
-
|
|
241125
|
-
const name = atIndex > 0 ? value.slice(0, atIndex) : value;
|
|
241126
|
-
if (name === "pnpm" || name === "npm" || name === "yarn") {
|
|
241127
|
-
return name;
|
|
241128
|
-
}
|
|
241129
|
-
return null;
|
|
241089
|
+
const atIndex = value.indexOf("@"), name = atIndex > 0 ? value.slice(0, atIndex) : value;
|
|
241090
|
+
return name === "pnpm" || name === "npm" || name === "yarn" ? name : null;
|
|
241130
241091
|
}
|
|
241131
241092
|
__name(parsePackageManagerField, "parsePackageManagerField");
|
|
241132
241093
|
function detectByPackageJson(projectDir) {
|
|
241133
241094
|
const pkgPath = (0, import_node_path3.join)(projectDir, "package.json");
|
|
241134
|
-
if (!(0, import_node_fs2.existsSync)(pkgPath))
|
|
241095
|
+
if (!(0, import_node_fs2.existsSync)(pkgPath))
|
|
241135
241096
|
return null;
|
|
241136
|
-
}
|
|
241137
241097
|
try {
|
|
241138
|
-
const content = (0, import_node_fs2.readFileSync)(pkgPath, "utf-8");
|
|
241139
|
-
const pkg = JSON.parse(content);
|
|
241098
|
+
const content = (0, import_node_fs2.readFileSync)(pkgPath, "utf-8"), pkg = JSON.parse(content);
|
|
241140
241099
|
return parsePackageManagerField(pkg.packageManager);
|
|
241141
241100
|
} catch {
|
|
241142
241101
|
return null;
|
|
@@ -241172,23 +241131,18 @@ function createPackageManagerInfo(name, lockfile) {
|
|
|
241172
241131
|
__name(createPackageManagerInfo, "createPackageManagerInfo");
|
|
241173
241132
|
function detectPackageManager(projectDir) {
|
|
241174
241133
|
const lockfileResult = detectByLockfile(projectDir);
|
|
241175
|
-
if (lockfileResult)
|
|
241134
|
+
if (lockfileResult)
|
|
241176
241135
|
return createPackageManagerInfo(lockfileResult.pm, lockfileResult.lockfile);
|
|
241177
|
-
}
|
|
241178
241136
|
const fromField = detectByPackageJson(projectDir);
|
|
241179
|
-
|
|
241180
|
-
return createPackageManagerInfo(fromField, null);
|
|
241181
|
-
}
|
|
241182
|
-
return createPackageManagerInfo("npm", null);
|
|
241137
|
+
return createPackageManagerInfo(fromField || "npm", null);
|
|
241183
241138
|
}
|
|
241184
241139
|
__name(detectPackageManager, "detectPackageManager");
|
|
241185
241140
|
|
|
241186
241141
|
// dist/cli/dependency-check.js
|
|
241187
241142
|
function readPackageJson(dir) {
|
|
241188
241143
|
const pkgPath = (0, import_node_path4.join)(dir, "package.json");
|
|
241189
|
-
if (!(0, import_node_fs3.existsSync)(pkgPath))
|
|
241144
|
+
if (!(0, import_node_fs3.existsSync)(pkgPath))
|
|
241190
241145
|
return null;
|
|
241191
|
-
}
|
|
241192
241146
|
try {
|
|
241193
241147
|
const content = (0, import_node_fs3.readFileSync)(pkgPath, "utf-8");
|
|
241194
241148
|
return JSON.parse(content);
|
|
@@ -241204,42 +241158,31 @@ function checkPackageJsonDirect(pkg, packageName) {
|
|
|
241204
241158
|
pkg.peerDependencies,
|
|
241205
241159
|
pkg.optionalDependencies
|
|
241206
241160
|
];
|
|
241207
|
-
for (const deps of depTypes)
|
|
241208
|
-
if (deps && packageName in deps)
|
|
241161
|
+
for (const deps of depTypes)
|
|
241162
|
+
if (deps && packageName in deps)
|
|
241209
241163
|
return {
|
|
241210
241164
|
found: true,
|
|
241211
241165
|
version: deps[packageName],
|
|
241212
241166
|
source: "package.json"
|
|
241213
241167
|
};
|
|
241214
|
-
}
|
|
241215
|
-
}
|
|
241216
241168
|
return null;
|
|
241217
241169
|
}
|
|
241218
241170
|
__name(checkPackageJsonDirect, "checkPackageJsonDirect");
|
|
241219
241171
|
function execCommand(cmd, cwd) {
|
|
241220
241172
|
return new Promise((resolve2, reject) => {
|
|
241221
|
-
const [command, ...args] = cmd
|
|
241222
|
-
const proc = (0, import_node_child_process.spawn)(command, args, {
|
|
241173
|
+
const [command, ...args] = cmd, proc = (0, import_node_child_process.spawn)(command, args, {
|
|
241223
241174
|
cwd,
|
|
241224
241175
|
stdio: ["ignore", "pipe", "pipe"]
|
|
241225
241176
|
});
|
|
241226
|
-
let stdout = "";
|
|
241227
|
-
let stderr = "";
|
|
241177
|
+
let stdout = "", stderr = "";
|
|
241228
241178
|
proc.stdout.on("data", (data) => {
|
|
241229
241179
|
stdout += data.toString();
|
|
241230
|
-
})
|
|
241231
|
-
proc.stderr.on("data", (data) => {
|
|
241180
|
+
}), proc.stderr.on("data", (data) => {
|
|
241232
241181
|
stderr += data.toString();
|
|
241233
|
-
})
|
|
241234
|
-
proc.on("error", (err) => {
|
|
241182
|
+
}), proc.on("error", (err) => {
|
|
241235
241183
|
reject(err);
|
|
241236
|
-
})
|
|
241237
|
-
|
|
241238
|
-
if (code === 0) {
|
|
241239
|
-
resolve2({ stdout, stderr });
|
|
241240
|
-
} else {
|
|
241241
|
-
reject(new Error(`Command failed with exit code ${code}: ${stderr}`));
|
|
241242
|
-
}
|
|
241184
|
+
}), proc.on("close", (code) => {
|
|
241185
|
+
code === 0 ? resolve2({ stdout, stderr }) : reject(new Error(`Command failed with exit code ${code}: ${stderr}`));
|
|
241243
241186
|
});
|
|
241244
241187
|
});
|
|
241245
241188
|
}
|
|
@@ -241247,15 +241190,11 @@ __name(execCommand, "execCommand");
|
|
|
241247
241190
|
function parsePnpmWhyOutput(stdout, packageName) {
|
|
241248
241191
|
try {
|
|
241249
241192
|
const result = JSON.parse(stdout);
|
|
241250
|
-
|
|
241251
|
-
|
|
241252
|
-
|
|
241253
|
-
|
|
241254
|
-
|
|
241255
|
-
source: "workspace"
|
|
241256
|
-
};
|
|
241257
|
-
}
|
|
241258
|
-
return null;
|
|
241193
|
+
return result && typeof result == "object" && packageName in result ? {
|
|
241194
|
+
found: true,
|
|
241195
|
+
version: result[packageName]?.version,
|
|
241196
|
+
source: "workspace"
|
|
241197
|
+
} : null;
|
|
241259
241198
|
} catch {
|
|
241260
241199
|
return null;
|
|
241261
241200
|
}
|
|
@@ -241264,15 +241203,11 @@ __name(parsePnpmWhyOutput, "parsePnpmWhyOutput");
|
|
|
241264
241203
|
function parseNpmWhyOutput(stdout, _packageName) {
|
|
241265
241204
|
try {
|
|
241266
241205
|
const result = JSON.parse(stdout);
|
|
241267
|
-
|
|
241268
|
-
|
|
241269
|
-
|
|
241270
|
-
|
|
241271
|
-
|
|
241272
|
-
source: "workspace"
|
|
241273
|
-
};
|
|
241274
|
-
}
|
|
241275
|
-
return null;
|
|
241206
|
+
return Array.isArray(result) && result.length > 0 ? {
|
|
241207
|
+
found: true,
|
|
241208
|
+
version: result[0]?.version,
|
|
241209
|
+
source: "workspace"
|
|
241210
|
+
} : null;
|
|
241276
241211
|
} catch {
|
|
241277
241212
|
return null;
|
|
241278
241213
|
}
|
|
@@ -241282,7 +241217,8 @@ function parseYarnWhyOutput(stdout, _packageName) {
|
|
|
241282
241217
|
if (stdout.trim().length > 0) {
|
|
241283
241218
|
let version;
|
|
241284
241219
|
try {
|
|
241285
|
-
const lines = stdout.trim().split(
|
|
241220
|
+
const lines = stdout.trim().split(`
|
|
241221
|
+
`);
|
|
241286
241222
|
for (const line of lines) {
|
|
241287
241223
|
const obj = JSON.parse(line);
|
|
241288
241224
|
if (obj.type === "info" && obj.data) {
|
|
@@ -241322,31 +241258,21 @@ async function checkViaPackageManager(pm, packageName, cwd) {
|
|
|
241322
241258
|
}
|
|
241323
241259
|
__name(checkViaPackageManager, "checkViaPackageManager");
|
|
241324
241260
|
async function checkDependencies(projectDir) {
|
|
241325
|
-
const pm = detectPackageManager(projectDir);
|
|
241326
|
-
|
|
241327
|
-
let thinkwellStatus = { found: false };
|
|
241328
|
-
let typescriptStatus = { found: false };
|
|
241261
|
+
const pm = detectPackageManager(projectDir), pkg = readPackageJson(projectDir);
|
|
241262
|
+
let thinkwellStatus = { found: false }, typescriptStatus = { found: false };
|
|
241329
241263
|
if (pkg) {
|
|
241330
241264
|
const thinkwellDirect = checkPackageJsonDirect(pkg, "thinkwell");
|
|
241331
|
-
|
|
241332
|
-
thinkwellStatus = thinkwellDirect;
|
|
241333
|
-
}
|
|
241265
|
+
thinkwellDirect && (thinkwellStatus = thinkwellDirect);
|
|
241334
241266
|
const typescriptDirect = checkPackageJsonDirect(pkg, "typescript");
|
|
241335
|
-
|
|
241336
|
-
typescriptStatus = typescriptDirect;
|
|
241337
|
-
}
|
|
241267
|
+
typescriptDirect && (typescriptStatus = typescriptDirect);
|
|
241338
241268
|
}
|
|
241339
241269
|
if (!thinkwellStatus.found) {
|
|
241340
241270
|
const result = await checkViaPackageManager(pm, "thinkwell", projectDir);
|
|
241341
|
-
|
|
241342
|
-
thinkwellStatus = result;
|
|
241343
|
-
}
|
|
241271
|
+
result && (thinkwellStatus = result);
|
|
241344
241272
|
}
|
|
241345
241273
|
if (!typescriptStatus.found) {
|
|
241346
241274
|
const result = await checkViaPackageManager(pm, "typescript", projectDir);
|
|
241347
|
-
|
|
241348
|
-
typescriptStatus = result;
|
|
241349
|
-
}
|
|
241275
|
+
result && (typescriptStatus = result);
|
|
241350
241276
|
}
|
|
241351
241277
|
return {
|
|
241352
241278
|
thinkwell: thinkwellStatus,
|
|
@@ -241357,14 +241283,12 @@ async function checkDependencies(projectDir) {
|
|
|
241357
241283
|
__name(checkDependencies, "checkDependencies");
|
|
241358
241284
|
function findProjectRoot(startDir) {
|
|
241359
241285
|
let dir = startDir;
|
|
241360
|
-
|
|
241361
|
-
if ((0, import_node_fs3.existsSync)((0, import_node_path4.join)(dir, "package.json")))
|
|
241286
|
+
for (; ; ) {
|
|
241287
|
+
if ((0, import_node_fs3.existsSync)((0, import_node_path4.join)(dir, "package.json")))
|
|
241362
241288
|
return dir;
|
|
241363
|
-
}
|
|
241364
241289
|
const parent = (0, import_node_path4.dirname)(dir);
|
|
241365
|
-
if (parent === dir)
|
|
241366
|
-
return
|
|
241367
|
-
}
|
|
241290
|
+
if (parent === dir)
|
|
241291
|
+
return;
|
|
241368
241292
|
dir = parent;
|
|
241369
241293
|
}
|
|
241370
241294
|
}
|
|
@@ -241372,55 +241296,23 @@ __name(findProjectRoot, "findProjectRoot");
|
|
|
241372
241296
|
|
|
241373
241297
|
// dist/cli/dependency-errors.js
|
|
241374
241298
|
function formatMissingDependencyError(result) {
|
|
241375
|
-
const { thinkwell, typescript, packageManager } = result;
|
|
241376
|
-
|
|
241377
|
-
const missing = [];
|
|
241378
|
-
if (!thinkwell.found)
|
|
241379
|
-
missing.push("thinkwell");
|
|
241380
|
-
if (!typescript.found)
|
|
241381
|
-
missing.push("typescript");
|
|
241382
|
-
if (missing.length === 0) {
|
|
241299
|
+
const { thinkwell, typescript, packageManager } = result, pm = packageManager, missing = [];
|
|
241300
|
+
if (thinkwell.found || missing.push("thinkwell"), typescript.found || missing.push("typescript"), missing.length === 0)
|
|
241383
241301
|
return "";
|
|
241384
|
-
}
|
|
241385
241302
|
const lines = [];
|
|
241386
|
-
|
|
241387
|
-
|
|
241388
|
-
} else {
|
|
241389
|
-
lines.push(`Error: This project has a package.json but is missing required dependencies.`);
|
|
241390
|
-
}
|
|
241391
|
-
lines.push("");
|
|
241392
|
-
lines.push("When a project has explicit configuration, thinkwell expects explicit dependencies.");
|
|
241393
|
-
lines.push("This ensures you get the versions you expect, not versions bundled with the CLI.");
|
|
241394
|
-
lines.push("");
|
|
241395
|
-
lines.push("Run 'thinkwell init' to add the required dependencies, or add them manually:");
|
|
241396
|
-
if (!thinkwell.found) {
|
|
241397
|
-
lines.push(` ${pm.addCommand("thinkwell")}`);
|
|
241398
|
-
}
|
|
241399
|
-
if (!typescript.found) {
|
|
241400
|
-
lines.push(` ${pm.addCommand("typescript", true)}`);
|
|
241401
|
-
}
|
|
241402
|
-
return lines.join("\n");
|
|
241303
|
+
return missing.length === 1 ? lines.push(`Error: This project has a package.json but no dependency on '${missing[0]}'.`) : lines.push("Error: This project has a package.json but is missing required dependencies."), lines.push(""), lines.push("When a project has explicit configuration, thinkwell expects explicit dependencies."), lines.push("This ensures you get the versions you expect, not versions bundled with the CLI."), lines.push(""), lines.push("Run 'thinkwell init' to add the required dependencies, or add them manually:"), thinkwell.found || lines.push(` ${pm.addCommand("thinkwell")}`), typescript.found || lines.push(` ${pm.addCommand("typescript", true)}`), lines.join(`
|
|
241304
|
+
`);
|
|
241403
241305
|
}
|
|
241404
241306
|
__name(formatMissingDependencyError, "formatMissingDependencyError");
|
|
241405
241307
|
function hasMissingDeps(result, options) {
|
|
241406
|
-
|
|
241407
|
-
return true;
|
|
241408
|
-
if (options.requireTypescript && !result.typescript.found)
|
|
241409
|
-
return true;
|
|
241410
|
-
return false;
|
|
241308
|
+
return !!(!result.thinkwell.found || options.requireTypescript && !result.typescript.found);
|
|
241411
241309
|
}
|
|
241412
241310
|
__name(hasMissingDeps, "hasMissingDeps");
|
|
241413
241311
|
function formatMissingDepsError(result, options) {
|
|
241414
|
-
|
|
241415
|
-
|
|
241416
|
-
|
|
241417
|
-
|
|
241418
|
-
return formatMissingDependencyError({
|
|
241419
|
-
...result,
|
|
241420
|
-
typescript: { found: true }
|
|
241421
|
-
});
|
|
241422
|
-
}
|
|
241423
|
-
return formatMissingDependencyError(result);
|
|
241312
|
+
return !options.requireTypescript && result.thinkwell.found ? "" : options.requireTypescript ? formatMissingDependencyError(result) : formatMissingDependencyError({
|
|
241313
|
+
...result,
|
|
241314
|
+
typescript: { found: true }
|
|
241315
|
+
});
|
|
241424
241316
|
}
|
|
241425
241317
|
__name(formatMissingDepsError, "formatMissingDepsError");
|
|
241426
241318
|
|
|
@@ -241429,26 +241321,16 @@ var import_meta = {};
|
|
|
241429
241321
|
var SPINNER_FRAMES = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
|
|
241430
241322
|
var SPINNER_INTERVAL = 80;
|
|
241431
241323
|
function createSpinnerImpl(options) {
|
|
241432
|
-
let text = options.text;
|
|
241433
|
-
|
|
241434
|
-
|
|
241435
|
-
|
|
241436
|
-
|
|
241437
|
-
const clearLine = /* @__PURE__ */ __name(() => {
|
|
241438
|
-
if (isTTY()) {
|
|
241439
|
-
process.stderr.write("\r\x1B[K");
|
|
241440
|
-
}
|
|
241441
|
-
}, "clearLine");
|
|
241442
|
-
const render = /* @__PURE__ */ __name(() => {
|
|
241443
|
-
if (isSilent)
|
|
241444
|
-
return;
|
|
241445
|
-
if (isTTY()) {
|
|
241324
|
+
let text = options.text, interval, frameIndex = 0;
|
|
241325
|
+
const isSilent = options.isSilent ?? false, isTTY = /* @__PURE__ */ __name(() => process.stderr.isTTY === true, "isTTY"), clearLine = /* @__PURE__ */ __name(() => {
|
|
241326
|
+
isTTY() && process.stderr.write("\r\x1B[K");
|
|
241327
|
+
}, "clearLine"), render = /* @__PURE__ */ __name(() => {
|
|
241328
|
+
if (!isSilent && isTTY()) {
|
|
241446
241329
|
const frame = SPINNER_FRAMES[frameIndex % SPINNER_FRAMES.length];
|
|
241447
|
-
process.stderr.write(`\r${frame} ${text}`)
|
|
241448
|
-
frameIndex++;
|
|
241330
|
+
process.stderr.write(`\r${frame} ${text}`), frameIndex++;
|
|
241449
241331
|
}
|
|
241450
241332
|
}, "render");
|
|
241451
|
-
|
|
241333
|
+
return {
|
|
241452
241334
|
get text() {
|
|
241453
241335
|
return text;
|
|
241454
241336
|
},
|
|
@@ -241456,66 +241338,32 @@ function createSpinnerImpl(options) {
|
|
|
241456
241338
|
text = value;
|
|
241457
241339
|
},
|
|
241458
241340
|
start(newText) {
|
|
241459
|
-
|
|
241460
|
-
|
|
241461
|
-
if (isSilent)
|
|
241462
|
-
return this;
|
|
241463
|
-
if (isTTY()) {
|
|
241464
|
-
render();
|
|
241465
|
-
interval = setInterval(render, SPINNER_INTERVAL);
|
|
241466
|
-
} else {
|
|
241467
|
-
process.stderr.write(`- ${text}
|
|
241468
|
-
`);
|
|
241469
|
-
}
|
|
241470
|
-
return this;
|
|
241341
|
+
return newText && (text = newText), isSilent ? this : (isTTY() ? (render(), interval = setInterval(render, SPINNER_INTERVAL)) : process.stderr.write(`- ${text}
|
|
241342
|
+
`), this);
|
|
241471
241343
|
},
|
|
241472
241344
|
stop() {
|
|
241473
|
-
|
|
241474
|
-
clearInterval(interval);
|
|
241475
|
-
interval = void 0;
|
|
241476
|
-
}
|
|
241477
|
-
clearLine();
|
|
241478
|
-
return this;
|
|
241345
|
+
return interval && (clearInterval(interval), interval = void 0), clearLine(), this;
|
|
241479
241346
|
},
|
|
241480
241347
|
succeed(successText) {
|
|
241481
|
-
if (interval)
|
|
241482
|
-
clearInterval(interval);
|
|
241483
|
-
interval = void 0;
|
|
241484
|
-
}
|
|
241485
|
-
if (isSilent)
|
|
241348
|
+
if (interval && (clearInterval(interval), interval = void 0), isSilent)
|
|
241486
241349
|
return this;
|
|
241487
241350
|
const finalText = successText ?? text;
|
|
241488
|
-
|
|
241489
|
-
|
|
241490
|
-
`);
|
|
241491
|
-
} else {
|
|
241492
|
-
process.stderr.write(`\u2714 ${finalText}
|
|
241493
|
-
`);
|
|
241494
|
-
}
|
|
241495
|
-
return this;
|
|
241351
|
+
return isTTY() ? process.stderr.write(`\r\x1B[K\u2714 ${finalText}
|
|
241352
|
+
`) : process.stderr.write(`\u2714 ${finalText}
|
|
241353
|
+
`), this;
|
|
241496
241354
|
},
|
|
241497
241355
|
fail(failText) {
|
|
241498
|
-
if (interval)
|
|
241499
|
-
clearInterval(interval);
|
|
241500
|
-
interval = void 0;
|
|
241501
|
-
}
|
|
241502
|
-
if (isSilent)
|
|
241356
|
+
if (interval && (clearInterval(interval), interval = void 0), isSilent)
|
|
241503
241357
|
return this;
|
|
241504
241358
|
const finalText = failText ?? text;
|
|
241505
|
-
|
|
241506
|
-
|
|
241507
|
-
`);
|
|
241508
|
-
} else {
|
|
241509
|
-
process.stderr.write(`\u2716 ${finalText}
|
|
241510
|
-
`);
|
|
241511
|
-
}
|
|
241512
|
-
return this;
|
|
241359
|
+
return isTTY() ? process.stderr.write(`\r\x1B[K\u2716 ${finalText}
|
|
241360
|
+
`) : process.stderr.write(`\u2716 ${finalText}
|
|
241361
|
+
`), this;
|
|
241513
241362
|
}
|
|
241514
241363
|
};
|
|
241515
|
-
return spinner;
|
|
241516
241364
|
}
|
|
241517
241365
|
__name(createSpinnerImpl, "createSpinnerImpl");
|
|
241518
|
-
var __dirname2 = typeof import_meta?.url
|
|
241366
|
+
var __dirname2 = typeof import_meta?.url == "string" ? (0, import_node_path5.dirname)((0, import_node_url.fileURLToPath)(import_meta.url)) : globalThis.__dirname || (0, import_node_path5.dirname)(process.argv[1]);
|
|
241519
241367
|
var TARGET_MAP = {
|
|
241520
241368
|
"darwin-arm64": "node24-macos-arm64",
|
|
241521
241369
|
"darwin-x64": "node24-macos-x64",
|
|
@@ -241523,8 +241371,7 @@ var TARGET_MAP = {
|
|
|
241523
241371
|
"linux-arm64": "node24-linux-arm64"
|
|
241524
241372
|
};
|
|
241525
241373
|
function detectHostTarget() {
|
|
241526
|
-
const platform = process.platform;
|
|
241527
|
-
const arch = process.arch;
|
|
241374
|
+
const platform = process.platform, arch = process.arch;
|
|
241528
241375
|
if (platform === "darwin" && arch === "arm64")
|
|
241529
241376
|
return "darwin-arm64";
|
|
241530
241377
|
if (platform === "darwin" && arch === "x64")
|
|
@@ -241538,45 +241385,25 @@ function detectHostTarget() {
|
|
|
241538
241385
|
__name(detectHostTarget, "detectHostTarget");
|
|
241539
241386
|
function readPackageJsonConfig(dir) {
|
|
241540
241387
|
const pkgPath = (0, import_node_path5.join)(dir, "package.json");
|
|
241541
|
-
if (
|
|
241542
|
-
|
|
241543
|
-
|
|
241544
|
-
|
|
241545
|
-
|
|
241546
|
-
|
|
241547
|
-
|
|
241548
|
-
|
|
241549
|
-
|
|
241550
|
-
|
|
241551
|
-
|
|
241552
|
-
|
|
241553
|
-
|
|
241554
|
-
}
|
|
241555
|
-
if (Array.isArray(config.targets)) {
|
|
241556
|
-
const validTargets = ["darwin-arm64", "darwin-x64", "linux-x64", "linux-arm64", "host"];
|
|
241557
|
-
result.targets = config.targets.filter((t) => typeof t === "string" && validTargets.includes(t));
|
|
241558
|
-
}
|
|
241559
|
-
if (Array.isArray(config.include)) {
|
|
241560
|
-
result.include = config.include.filter((i) => typeof i === "string");
|
|
241561
|
-
}
|
|
241562
|
-
if (Array.isArray(config.external)) {
|
|
241563
|
-
result.external = config.external.filter((e) => typeof e === "string");
|
|
241564
|
-
}
|
|
241565
|
-
if (typeof config.minify === "boolean") {
|
|
241566
|
-
result.minify = config.minify;
|
|
241388
|
+
if ((0, import_node_fs4.existsSync)(pkgPath))
|
|
241389
|
+
try {
|
|
241390
|
+
const content = (0, import_node_fs4.readFileSync)(pkgPath, "utf-8"), config = JSON.parse(content)?.thinkwell?.bundle;
|
|
241391
|
+
if (!config || typeof config != "object")
|
|
241392
|
+
return;
|
|
241393
|
+
const result = {};
|
|
241394
|
+
if (typeof config.output == "string" && (result.output = config.output), Array.isArray(config.targets)) {
|
|
241395
|
+
const validTargets = ["darwin-arm64", "darwin-x64", "linux-x64", "linux-arm64", "host"];
|
|
241396
|
+
result.targets = config.targets.filter((t) => typeof t == "string" && validTargets.includes(t));
|
|
241397
|
+
}
|
|
241398
|
+
return Array.isArray(config.include) && (result.include = config.include.filter((i) => typeof i == "string")), Array.isArray(config.external) && (result.external = config.external.filter((e) => typeof e == "string")), typeof config.minify == "boolean" && (result.minify = config.minify), result;
|
|
241399
|
+
} catch {
|
|
241400
|
+
return;
|
|
241567
241401
|
}
|
|
241568
|
-
return result;
|
|
241569
|
-
} catch {
|
|
241570
|
-
return void 0;
|
|
241571
|
-
}
|
|
241572
241402
|
}
|
|
241573
241403
|
__name(readPackageJsonConfig, "readPackageJsonConfig");
|
|
241574
241404
|
function mergeWithPackageConfig(options, entryDir) {
|
|
241575
241405
|
const pkgConfig = readPackageJsonConfig(entryDir);
|
|
241576
|
-
|
|
241577
|
-
return options;
|
|
241578
|
-
}
|
|
241579
|
-
return {
|
|
241406
|
+
return pkgConfig ? {
|
|
241580
241407
|
...options,
|
|
241581
241408
|
output: options.output ?? pkgConfig.output,
|
|
241582
241409
|
targets: options.targets && options.targets.length > 0 ? options.targets : pkgConfig.targets ?? options.targets,
|
|
@@ -241589,7 +241416,7 @@ function mergeWithPackageConfig(options, entryDir) {
|
|
|
241589
241416
|
...options.external || []
|
|
241590
241417
|
],
|
|
241591
241418
|
minify: options.minify ?? pkgConfig.minify
|
|
241592
|
-
};
|
|
241419
|
+
} : options;
|
|
241593
241420
|
}
|
|
241594
241421
|
__name(mergeWithPackageConfig, "mergeWithPackageConfig");
|
|
241595
241422
|
function parseBundleArgs(args) {
|
|
@@ -241600,88 +241427,68 @@ function parseBundleArgs(args) {
|
|
|
241600
241427
|
external: []
|
|
241601
241428
|
};
|
|
241602
241429
|
let i = 0;
|
|
241603
|
-
|
|
241430
|
+
for (; i < args.length; ) {
|
|
241604
241431
|
const arg = args[i];
|
|
241605
241432
|
if (arg === "-o" || arg === "--output") {
|
|
241606
|
-
i
|
|
241607
|
-
if (i >= args.length) {
|
|
241433
|
+
if (i++, i >= args.length)
|
|
241608
241434
|
throw new Error("Missing value for --output");
|
|
241609
|
-
}
|
|
241610
241435
|
options.output = args[i];
|
|
241611
241436
|
} else if (arg === "-t" || arg === "--target") {
|
|
241612
|
-
i
|
|
241613
|
-
if (i >= args.length) {
|
|
241437
|
+
if (i++, i >= args.length)
|
|
241614
241438
|
throw new Error("Missing value for --target");
|
|
241615
|
-
|
|
241616
|
-
|
|
241617
|
-
const validTargets = ["darwin-arm64", "darwin-x64", "linux-x64", "linux-arm64", "host"];
|
|
241618
|
-
if (!validTargets.includes(target2)) {
|
|
241439
|
+
const target2 = args[i], validTargets = ["darwin-arm64", "darwin-x64", "linux-x64", "linux-arm64", "host"];
|
|
241440
|
+
if (!validTargets.includes(target2))
|
|
241619
241441
|
throw new Error(`Invalid target '${target2}'. Valid targets: ${validTargets.join(", ")}`);
|
|
241620
|
-
}
|
|
241621
241442
|
options.targets.push(target2);
|
|
241622
241443
|
} else if (arg === "--include") {
|
|
241623
|
-
i
|
|
241624
|
-
if (i >= args.length) {
|
|
241444
|
+
if (i++, i >= args.length)
|
|
241625
241445
|
throw new Error("Missing value for --include");
|
|
241626
|
-
}
|
|
241627
241446
|
options.include.push(args[i]);
|
|
241628
241447
|
} else if (arg === "--external" || arg === "-e") {
|
|
241629
|
-
i
|
|
241630
|
-
if (i >= args.length) {
|
|
241448
|
+
if (i++, i >= args.length)
|
|
241631
241449
|
throw new Error("Missing value for --external");
|
|
241632
|
-
}
|
|
241633
241450
|
options.external.push(args[i]);
|
|
241634
|
-
} else if (arg === "--verbose" || arg === "-v")
|
|
241451
|
+
} else if (arg === "--verbose" || arg === "-v")
|
|
241635
241452
|
options.verbose = true;
|
|
241636
|
-
|
|
241453
|
+
else if (arg === "--quiet" || arg === "-q")
|
|
241637
241454
|
options.quiet = true;
|
|
241638
|
-
|
|
241455
|
+
else if (arg === "--dry-run" || arg === "-n")
|
|
241639
241456
|
options.dryRun = true;
|
|
241640
|
-
|
|
241457
|
+
else if (arg === "--minify" || arg === "-m")
|
|
241641
241458
|
options.minify = true;
|
|
241642
|
-
|
|
241459
|
+
else if (arg === "--watch" || arg === "-w")
|
|
241643
241460
|
options.watch = true;
|
|
241644
|
-
|
|
241645
|
-
|
|
241646
|
-
|
|
241647
|
-
if (options.entry)
|
|
241461
|
+
else {
|
|
241462
|
+
if (arg.startsWith("-"))
|
|
241463
|
+
throw new Error(`Unknown option: ${arg}`);
|
|
241464
|
+
if (options.entry)
|
|
241648
241465
|
throw new Error(`Unexpected argument: ${arg}`);
|
|
241649
|
-
}
|
|
241650
241466
|
options.entry = arg;
|
|
241651
241467
|
}
|
|
241652
241468
|
i++;
|
|
241653
241469
|
}
|
|
241654
|
-
if (!options.entry)
|
|
241470
|
+
if (!options.entry)
|
|
241655
241471
|
throw new Error("No entry file specified");
|
|
241656
|
-
|
|
241657
|
-
if (options.targets.length === 0) {
|
|
241658
|
-
options.targets = ["host"];
|
|
241659
|
-
}
|
|
241660
|
-
return options;
|
|
241472
|
+
return options.targets.length === 0 && (options.targets = ["host"]), options;
|
|
241661
241473
|
}
|
|
241662
241474
|
__name(parseBundleArgs, "parseBundleArgs");
|
|
241663
241475
|
function initBundleContext(options) {
|
|
241664
241476
|
const entryPath = (0, import_node_path5.isAbsolute)(options.entry) ? options.entry : (0, import_node_path5.resolve)(process.cwd(), options.entry);
|
|
241665
241477
|
if (!(0, import_node_fs4.existsSync)(entryPath)) {
|
|
241666
|
-
const suggestion = options.entry.endsWith(".ts") || options.entry.endsWith(".js") ? "" :
|
|
241478
|
+
const suggestion = options.entry.endsWith(".ts") || options.entry.endsWith(".js") ? "" : `
|
|
241479
|
+
Did you mean to add a .ts or .js extension?`;
|
|
241667
241480
|
throw new Error(`Entry file not found: ${options.entry}${suggestion}
|
|
241668
241481
|
Working directory: ${process.cwd()}`);
|
|
241669
241482
|
}
|
|
241670
|
-
const entryBasename = (0, import_node_path5.basename)(entryPath).replace(/\.(ts|js|mts|mjs|cts|cjs)$/, "");
|
|
241671
|
-
const entryDir = (0, import_node_path5.dirname)(entryPath);
|
|
241483
|
+
const entryBasename = (0, import_node_path5.basename)(entryPath).replace(/\.(ts|js|mts|mjs|cts|cjs)$/, ""), entryDir = (0, import_node_path5.dirname)(entryPath);
|
|
241672
241484
|
let mergedOptions = mergeWithPackageConfig(options, entryDir);
|
|
241673
|
-
|
|
241674
|
-
|
|
241675
|
-
|
|
241676
|
-
const buildDir = (0, import_node_fs4.mkdtempSync)((0, import_node_path5.join)((0, import_node_os.tmpdir)(), `thinkwell-bundle-${entryBasename}-`));
|
|
241677
|
-
const thinkwellDistPkg = (0, import_node_path5.resolve)(__dirname2, "../../dist-pkg");
|
|
241678
|
-
if (!(0, import_node_fs4.existsSync)(thinkwellDistPkg)) {
|
|
241485
|
+
entryDir !== process.cwd() && (mergedOptions = mergeWithPackageConfig(mergedOptions, process.cwd()));
|
|
241486
|
+
const buildDir = (0, import_node_fs4.mkdtempSync)((0, import_node_path5.join)((0, import_node_os.tmpdir)(), `thinkwell-bundle-${entryBasename}-`)), thinkwellDistPkg = (0, import_node_path5.resolve)(__dirname2, "../../dist-pkg");
|
|
241487
|
+
if (!(0, import_node_fs4.existsSync)(thinkwellDistPkg))
|
|
241679
241488
|
throw new Error(`Thinkwell dist-pkg not found at ${thinkwellDistPkg}.
|
|
241680
241489
|
This may indicate a corrupted installation.
|
|
241681
241490
|
Try reinstalling thinkwell: npm install thinkwell`);
|
|
241682
|
-
|
|
241683
|
-
const resolvedTargets = mergedOptions.targets.map((t) => t === "host" ? detectHostTarget() : t);
|
|
241684
|
-
const uniqueTargets = [...new Set(resolvedTargets)];
|
|
241491
|
+
const resolvedTargets = mergedOptions.targets.map((t) => t === "host" ? detectHostTarget() : t), uniqueTargets = [...new Set(resolvedTargets)];
|
|
241685
241492
|
return {
|
|
241686
241493
|
entryPath,
|
|
241687
241494
|
entryBasename,
|
|
@@ -241694,16 +241501,7 @@ function initBundleContext(options) {
|
|
|
241694
241501
|
}
|
|
241695
241502
|
__name(initBundleContext, "initBundleContext");
|
|
241696
241503
|
function getOutputPath(ctx, target2) {
|
|
241697
|
-
|
|
241698
|
-
if (ctx.resolvedTargets.length === 1) {
|
|
241699
|
-
return (0, import_node_path5.isAbsolute)(ctx.options.output) ? ctx.options.output : (0, import_node_path5.resolve)(process.cwd(), ctx.options.output);
|
|
241700
|
-
} else {
|
|
241701
|
-
const base = (0, import_node_path5.isAbsolute)(ctx.options.output) ? ctx.options.output : (0, import_node_path5.resolve)(process.cwd(), ctx.options.output);
|
|
241702
|
-
return `${base}-${target2}`;
|
|
241703
|
-
}
|
|
241704
|
-
} else {
|
|
241705
|
-
return (0, import_node_path5.resolve)(process.cwd(), `${ctx.entryBasename}-${target2}`);
|
|
241706
|
-
}
|
|
241504
|
+
return ctx.options.output ? ctx.resolvedTargets.length === 1 ? (0, import_node_path5.isAbsolute)(ctx.options.output) ? ctx.options.output : (0, import_node_path5.resolve)(process.cwd(), ctx.options.output) : `${(0, import_node_path5.isAbsolute)(ctx.options.output) ? ctx.options.output : (0, import_node_path5.resolve)(process.cwd(), ctx.options.output)}-${target2}` : (0, import_node_path5.resolve)(process.cwd(), `${ctx.entryBasename}-${target2}`);
|
|
241707
241505
|
}
|
|
241708
241506
|
__name(getOutputPath, "getOutputPath");
|
|
241709
241507
|
function generateWrapperSource(userBundlePath) {
|
|
@@ -241731,9 +241529,7 @@ require('./${(0, import_node_path5.basename)(userBundlePath)}');
|
|
|
241731
241529
|
__name(generateWrapperSource, "generateWrapperSource");
|
|
241732
241530
|
async function bundleUserScript(ctx) {
|
|
241733
241531
|
const outputFile = (0, import_node_path5.join)(ctx.buildDir, `${ctx.entryBasename}-bundle.cjs`);
|
|
241734
|
-
|
|
241735
|
-
console.log(` Bundling ${ctx.entryPath}...`);
|
|
241736
|
-
}
|
|
241532
|
+
ctx.options.verbose && console.log(` Bundling ${ctx.entryPath}...`);
|
|
241737
241533
|
try {
|
|
241738
241534
|
const externalPackages = ["node:*", ...ctx.options.external || []];
|
|
241739
241535
|
await esbuild.build({
|
|
@@ -241776,27 +241572,20 @@ require.main = __origRequire.main;
|
|
|
241776
241572
|
name: "jsonschema-transformer",
|
|
241777
241573
|
setup(build2) {
|
|
241778
241574
|
build2.onLoad({ filter: /\.(ts|tsx|mts|cts)$/ }, async (args) => {
|
|
241779
|
-
if (args.path.includes("node_modules"))
|
|
241575
|
+
if (args.path.includes("node_modules"))
|
|
241780
241576
|
return null;
|
|
241781
|
-
}
|
|
241782
241577
|
const source = (0, import_node_fs4.readFileSync)(args.path, "utf-8");
|
|
241783
|
-
|
|
241784
|
-
|
|
241785
|
-
}
|
|
241786
|
-
const transformed = transformJsonSchemas(args.path, source, ctx.projectDir);
|
|
241787
|
-
return {
|
|
241788
|
-
contents: transformed,
|
|
241578
|
+
return hasJsonSchemaMarkers(source) ? {
|
|
241579
|
+
contents: transformJsonSchemas(args.path, source, ctx.projectDir),
|
|
241789
241580
|
loader: args.path.endsWith(".tsx") ? "tsx" : "ts"
|
|
241790
|
-
};
|
|
241581
|
+
} : null;
|
|
241791
241582
|
});
|
|
241792
241583
|
}
|
|
241793
241584
|
},
|
|
241794
241585
|
{
|
|
241795
241586
|
name: "thinkwell-resolver",
|
|
241796
241587
|
setup(build2) {
|
|
241797
|
-
build2.onResolve({ filter: /^(thinkwell|@thinkwell\/(acp|protocol))$/ }, (args) => {
|
|
241798
|
-
return { path: args.path, external: true };
|
|
241799
|
-
});
|
|
241588
|
+
build2.onResolve({ filter: /^(thinkwell|@thinkwell\/(acp|protocol))$/ }, (args) => ({ path: args.path, external: true }));
|
|
241800
241589
|
}
|
|
241801
241590
|
}
|
|
241802
241591
|
],
|
|
@@ -241810,18 +241599,14 @@ require.main = __origRequire.main;
|
|
|
241810
241599
|
} catch (error) {
|
|
241811
241600
|
const message = error instanceof Error ? error.message : String(error);
|
|
241812
241601
|
if (message.includes("Could not resolve")) {
|
|
241813
|
-
const match = message.match(/Could not resolve "([^"]+)"/);
|
|
241814
|
-
const moduleName = match ? match[1] : "unknown module";
|
|
241602
|
+
const match = message.match(/Could not resolve "([^"]+)"/), moduleName = match ? match[1] : "unknown module";
|
|
241815
241603
|
throw new Error(`Could not resolve dependency "${moduleName}".
|
|
241816
241604
|
Make sure all dependencies are installed: npm install
|
|
241817
241605
|
If this is a dev dependency, it may need to be a regular dependency.`);
|
|
241818
241606
|
}
|
|
241819
|
-
|
|
241820
|
-
throw new Error(`Unsupported file type in import.
|
|
241607
|
+
throw message.includes("No loader is configured") ? new Error(`Unsupported file type in import.
|
|
241821
241608
|
esbuild cannot bundle this file type by default.
|
|
241822
|
-
Consider using --include to embed the file as an asset instead.`);
|
|
241823
|
-
}
|
|
241824
|
-
throw error;
|
|
241609
|
+
Consider using --include to embed the file as an asset instead.`) : error;
|
|
241825
241610
|
}
|
|
241826
241611
|
return outputFile;
|
|
241827
241612
|
}
|
|
@@ -241829,21 +241614,16 @@ __name(bundleUserScript, "bundleUserScript");
|
|
|
241829
241614
|
function copyThinkwellBundles(ctx) {
|
|
241830
241615
|
const bundles = ["thinkwell.cjs", "acp.cjs", "protocol.cjs"];
|
|
241831
241616
|
for (const bundle of bundles) {
|
|
241832
|
-
const src = (0, import_node_path5.join)(ctx.thinkwellDistPkg, bundle);
|
|
241833
|
-
|
|
241834
|
-
if (!(0, import_node_fs4.existsSync)(src)) {
|
|
241617
|
+
const src = (0, import_node_path5.join)(ctx.thinkwellDistPkg, bundle), dest = (0, import_node_path5.join)(ctx.buildDir, bundle);
|
|
241618
|
+
if (!(0, import_node_fs4.existsSync)(src))
|
|
241835
241619
|
throw new Error(`Thinkwell bundle not found: ${src}`);
|
|
241836
|
-
}
|
|
241837
241620
|
const content = (0, import_node_fs4.readFileSync)(src);
|
|
241838
|
-
(0, import_node_fs4.writeFileSync)(dest, content);
|
|
241839
|
-
if (ctx.options.verbose) {
|
|
241840
|
-
console.log(` Copied ${bundle}`);
|
|
241841
|
-
}
|
|
241621
|
+
(0, import_node_fs4.writeFileSync)(dest, content), ctx.options.verbose && console.log(` Copied ${bundle}`);
|
|
241842
241622
|
}
|
|
241843
241623
|
}
|
|
241844
241624
|
__name(copyThinkwellBundles, "copyThinkwellBundles");
|
|
241845
241625
|
function isRunningFromCompiledBinary() {
|
|
241846
|
-
return typeof process.pkg
|
|
241626
|
+
return typeof process.pkg < "u";
|
|
241847
241627
|
}
|
|
241848
241628
|
__name(isRunningFromCompiledBinary, "isRunningFromCompiledBinary");
|
|
241849
241629
|
var PORTABLE_NODE_VERSION = "24.1.0";
|
|
@@ -241854,44 +241634,34 @@ __name(getCacheDir, "getCacheDir");
|
|
|
241854
241634
|
function getThinkwellVersion() {
|
|
241855
241635
|
try {
|
|
241856
241636
|
const pkgPath = (0, import_node_path5.resolve)(__dirname2, "../../package.json");
|
|
241857
|
-
|
|
241858
|
-
return pkg.version || "unknown";
|
|
241637
|
+
return JSON.parse((0, import_node_fs4.readFileSync)(pkgPath, "utf-8")).version || "unknown";
|
|
241859
241638
|
} catch {
|
|
241860
241639
|
return "unknown";
|
|
241861
241640
|
}
|
|
241862
241641
|
}
|
|
241863
241642
|
__name(getThinkwellVersion, "getThinkwellVersion");
|
|
241864
241643
|
function getNodePlatformArch() {
|
|
241865
|
-
const platform = process.platform === "darwin" ? "darwin" : "linux";
|
|
241866
|
-
const arch = process.arch;
|
|
241644
|
+
const platform = process.platform === "darwin" ? "darwin" : "linux", arch = process.arch;
|
|
241867
241645
|
return { platform, arch };
|
|
241868
241646
|
}
|
|
241869
241647
|
__name(getNodePlatformArch, "getNodePlatformArch");
|
|
241870
241648
|
async function downloadFile(url, destPath, spinner) {
|
|
241871
241649
|
const response = await fetch(url);
|
|
241872
|
-
if (!response.ok)
|
|
241650
|
+
if (!response.ok)
|
|
241873
241651
|
throw new Error(`Failed to download ${url}: ${response.status} ${response.statusText}`);
|
|
241874
|
-
|
|
241875
|
-
const contentLength = response.headers.get("content-length");
|
|
241876
|
-
const totalBytes = contentLength ? parseInt(contentLength, 10) : 0;
|
|
241652
|
+
const contentLength = response.headers.get("content-length"), totalBytes = contentLength ? parseInt(contentLength, 10) : 0;
|
|
241877
241653
|
(0, import_node_fs4.mkdirSync)((0, import_node_path5.dirname)(destPath), { recursive: true });
|
|
241878
|
-
const fileStream = (0, import_node_fs4.createWriteStream)(destPath);
|
|
241879
|
-
|
|
241880
|
-
if (!reader) {
|
|
241654
|
+
const fileStream = (0, import_node_fs4.createWriteStream)(destPath), reader = response.body?.getReader();
|
|
241655
|
+
if (!reader)
|
|
241881
241656
|
throw new Error("No response body");
|
|
241882
|
-
}
|
|
241883
241657
|
let downloadedBytes = 0;
|
|
241884
241658
|
try {
|
|
241885
|
-
|
|
241659
|
+
for (; ; ) {
|
|
241886
241660
|
const { done, value } = await reader.read();
|
|
241887
241661
|
if (done)
|
|
241888
241662
|
break;
|
|
241889
|
-
fileStream.write(Buffer.from(value))
|
|
241890
|
-
|
|
241891
|
-
if (spinner && totalBytes > 0) {
|
|
241892
|
-
const percent = Math.round(downloadedBytes / totalBytes * 100);
|
|
241893
|
-
const downloadedMB = (downloadedBytes / 1024 / 1024).toFixed(1);
|
|
241894
|
-
const totalMB = (totalBytes / 1024 / 1024).toFixed(1);
|
|
241663
|
+
if (fileStream.write(Buffer.from(value)), downloadedBytes += value.length, spinner && totalBytes > 0) {
|
|
241664
|
+
const percent = Math.round(downloadedBytes / totalBytes * 100), downloadedMB = (downloadedBytes / 1024 / 1024).toFixed(1), totalMB = (totalBytes / 1024 / 1024).toFixed(1);
|
|
241895
241665
|
spinner.text = `Downloading Node.js runtime... ${downloadedMB} MB / ${totalMB} MB (${percent}%)`;
|
|
241896
241666
|
}
|
|
241897
241667
|
}
|
|
@@ -241899,8 +241669,7 @@ async function downloadFile(url, destPath, spinner) {
|
|
|
241899
241669
|
fileStream.end();
|
|
241900
241670
|
}
|
|
241901
241671
|
await new Promise((resolve2, reject) => {
|
|
241902
|
-
fileStream.on("finish", resolve2);
|
|
241903
|
-
fileStream.on("error", reject);
|
|
241672
|
+
fileStream.on("finish", resolve2), fileStream.on("error", reject);
|
|
241904
241673
|
});
|
|
241905
241674
|
}
|
|
241906
241675
|
__name(downloadFile, "downloadFile");
|
|
@@ -241910,17 +241679,15 @@ function hashFile(filePath) {
|
|
|
241910
241679
|
}
|
|
241911
241680
|
__name(hashFile, "hashFile");
|
|
241912
241681
|
async function fetchExpectedChecksum(version, filename) {
|
|
241913
|
-
const url = `https://nodejs.org/dist/v${version}/SHASUMS256.txt
|
|
241914
|
-
|
|
241915
|
-
if (!response.ok) {
|
|
241682
|
+
const url = `https://nodejs.org/dist/v${version}/SHASUMS256.txt`, response = await fetch(url);
|
|
241683
|
+
if (!response.ok)
|
|
241916
241684
|
throw new Error(`Failed to fetch checksums: ${response.status}`);
|
|
241917
|
-
}
|
|
241918
241685
|
const text = await response.text();
|
|
241919
|
-
for (const line of text.split(
|
|
241686
|
+
for (const line of text.split(`
|
|
241687
|
+
`)) {
|
|
241920
241688
|
const parts = line.trim().split(/\s+/);
|
|
241921
|
-
if (parts.length === 2 && parts[1] === filename)
|
|
241689
|
+
if (parts.length === 2 && parts[1] === filename)
|
|
241922
241690
|
return parts[0];
|
|
241923
|
-
}
|
|
241924
241691
|
}
|
|
241925
241692
|
throw new Error(`Checksum not found for ${filename}`);
|
|
241926
241693
|
}
|
|
@@ -241932,102 +241699,64 @@ function extractTarGz(archivePath, destDir) {
|
|
|
241932
241699
|
}
|
|
241933
241700
|
__name(extractTarGz, "extractTarGz");
|
|
241934
241701
|
async function ensurePortableNode(spinner) {
|
|
241935
|
-
const version = PORTABLE_NODE_VERSION;
|
|
241936
|
-
|
|
241937
|
-
const cacheDir = (0, import_node_path5.join)(getCacheDir(), "node", `v${version}`);
|
|
241938
|
-
const nodeBinary = process.platform === "win32" ? "node.exe" : "node";
|
|
241939
|
-
const nodePath = (0, import_node_path5.join)(cacheDir, nodeBinary);
|
|
241940
|
-
if ((0, import_node_fs4.existsSync)(nodePath)) {
|
|
241702
|
+
const version = PORTABLE_NODE_VERSION, { platform, arch } = getNodePlatformArch(), cacheDir = (0, import_node_path5.join)(getCacheDir(), "node", `v${version}`), nodeBinary = process.platform === "win32" ? "node.exe" : "node", nodePath = (0, import_node_path5.join)(cacheDir, nodeBinary);
|
|
241703
|
+
if ((0, import_node_fs4.existsSync)(nodePath))
|
|
241941
241704
|
return nodePath;
|
|
241942
|
-
}
|
|
241943
|
-
const filename = `node-v${version}-${platform}-${arch}.tar.gz`;
|
|
241944
|
-
const url = `https://nodejs.org/dist/v${version}/${filename}`;
|
|
241945
|
-
const archivePath = (0, import_node_path5.join)(cacheDir, filename);
|
|
241705
|
+
const filename = `node-v${version}-${platform}-${arch}.tar.gz`, url = `https://nodejs.org/dist/v${version}/${filename}`, archivePath = (0, import_node_path5.join)(cacheDir, filename);
|
|
241946
241706
|
spinner?.start("Downloading Node.js runtime (first time only)...");
|
|
241947
241707
|
try {
|
|
241948
|
-
(0, import_node_fs4.mkdirSync)(cacheDir, { recursive: true });
|
|
241949
|
-
await
|
|
241950
|
-
|
|
241951
|
-
|
|
241952
|
-
const actualHash = hashFile(archivePath);
|
|
241953
|
-
if (actualHash !== expectedHash) {
|
|
241954
|
-
(0, import_node_fs4.rmSync)(archivePath, { force: true });
|
|
241955
|
-
throw new Error(`Node.js download verification failed.
|
|
241708
|
+
(0, import_node_fs4.mkdirSync)(cacheDir, { recursive: true }), await downloadFile(url, archivePath, spinner), spinner?.start("Verifying download integrity...");
|
|
241709
|
+
const expectedHash = await fetchExpectedChecksum(version, filename), actualHash = hashFile(archivePath);
|
|
241710
|
+
if (actualHash !== expectedHash)
|
|
241711
|
+
throw (0, import_node_fs4.rmSync)(archivePath, { force: true }), new Error(`Node.js download verification failed.
|
|
241956
241712
|
|
|
241957
241713
|
Expected: ${expectedHash}
|
|
241958
241714
|
Actual: ${actualHash}
|
|
241959
241715
|
|
|
241960
241716
|
This may indicate a corrupted download or network interference.
|
|
241961
241717
|
Please retry or report this issue.`);
|
|
241962
|
-
|
|
241963
|
-
|
|
241964
|
-
|
|
241965
|
-
const extractedDir = (0, import_node_path5.join)(cacheDir, `node-v${version}-${platform}-${arch}`);
|
|
241966
|
-
const extractedBin = (0, import_node_path5.join)(extractedDir, "bin", nodeBinary);
|
|
241967
|
-
(0, import_node_fs4.copyFileSync)(extractedBin, nodePath);
|
|
241968
|
-
(0, import_node_fs4.chmodSync)(nodePath, 493);
|
|
241969
|
-
(0, import_node_fs4.rmSync)(extractedDir, { recursive: true, force: true });
|
|
241970
|
-
(0, import_node_fs4.rmSync)(archivePath, { force: true });
|
|
241971
|
-
spinner?.succeed(`Node.js v${version} cached to ${cacheDir}`);
|
|
241972
|
-
return nodePath;
|
|
241718
|
+
spinner?.start("Extracting Node.js..."), extractTarGz(archivePath, cacheDir);
|
|
241719
|
+
const extractedDir = (0, import_node_path5.join)(cacheDir, `node-v${version}-${platform}-${arch}`), extractedBin = (0, import_node_path5.join)(extractedDir, "bin", nodeBinary);
|
|
241720
|
+
return (0, import_node_fs4.copyFileSync)(extractedBin, nodePath), (0, import_node_fs4.chmodSync)(nodePath, 493), (0, import_node_fs4.rmSync)(extractedDir, { recursive: true, force: true }), (0, import_node_fs4.rmSync)(archivePath, { force: true }), spinner?.succeed(`Node.js v${version} cached to ${cacheDir}`), nodePath;
|
|
241973
241721
|
} catch (error) {
|
|
241974
241722
|
(0, import_node_fs4.rmSync)(cacheDir, { recursive: true, force: true });
|
|
241975
241723
|
const message = error instanceof Error ? error.message : String(error);
|
|
241976
|
-
|
|
241977
|
-
throw new Error(`Failed to download Node.js runtime.
|
|
241724
|
+
throw message.includes("ETIMEDOUT") || message.includes("ENOTFOUND") ? new Error(`Failed to download Node.js runtime.
|
|
241978
241725
|
|
|
241979
241726
|
URL: ${url}
|
|
241980
241727
|
Error: ${message}
|
|
241981
241728
|
|
|
241982
241729
|
Check your network connection and try again.
|
|
241983
|
-
If behind a proxy, set HTTPS_PROXY environment variable.`);
|
|
241984
|
-
}
|
|
241985
|
-
throw error;
|
|
241730
|
+
If behind a proxy, set HTTPS_PROXY environment variable.`) : error;
|
|
241986
241731
|
}
|
|
241987
241732
|
}
|
|
241988
241733
|
__name(ensurePortableNode, "ensurePortableNode");
|
|
241989
241734
|
function ensurePkgCli() {
|
|
241990
|
-
const version = getThinkwellVersion();
|
|
241991
|
-
|
|
241992
|
-
const cacheDir = (0, import_node_path5.join)(pkgCliBaseDir, version);
|
|
241993
|
-
const pkgCliPath = (0, import_node_path5.join)(cacheDir, "pkg-cli.cjs");
|
|
241994
|
-
const preludeCheck = (0, import_node_path5.join)(cacheDir, "pkg-prelude", "bootstrap.js");
|
|
241995
|
-
if ((0, import_node_fs4.existsSync)(pkgCliPath) && (0, import_node_fs4.existsSync)(preludeCheck)) {
|
|
241735
|
+
const version = getThinkwellVersion(), pkgCliBaseDir = (0, import_node_path5.join)(getCacheDir(), "pkg-cli"), cacheDir = (0, import_node_path5.join)(pkgCliBaseDir, version), pkgCliPath = (0, import_node_path5.join)(cacheDir, "pkg-cli.cjs"), preludeCheck = (0, import_node_path5.join)(cacheDir, "pkg-prelude", "bootstrap.js");
|
|
241736
|
+
if ((0, import_node_fs4.existsSync)(pkgCliPath) && (0, import_node_fs4.existsSync)(preludeCheck))
|
|
241996
241737
|
return pkgCliPath;
|
|
241997
|
-
|
|
241998
|
-
|
|
241999
|
-
const cliSrc = (0, import_node_path5.join)(distPkgPath, "pkg-cli.cjs");
|
|
242000
|
-
if (!(0, import_node_fs4.existsSync)(cliSrc)) {
|
|
241738
|
+
const distPkgPath = (0, import_node_path5.resolve)(__dirname2, "../../dist-pkg"), cliSrc = (0, import_node_path5.join)(distPkgPath, "pkg-cli.cjs");
|
|
241739
|
+
if (!(0, import_node_fs4.existsSync)(cliSrc))
|
|
242001
241740
|
throw new Error(`pkg CLI not found in compiled binary assets.
|
|
242002
241741
|
Expected at: ${cliSrc}
|
|
242003
241742
|
|
|
242004
241743
|
This may indicate a build issue. Please report this.`);
|
|
242005
|
-
}
|
|
242006
|
-
(0, import_node_fs4.mkdirSync)(cacheDir, { recursive: true });
|
|
242007
|
-
(0, import_node_fs4.copyFileSync)(cliSrc, pkgCliPath);
|
|
241744
|
+
(0, import_node_fs4.mkdirSync)(cacheDir, { recursive: true }), (0, import_node_fs4.copyFileSync)(cliSrc, pkgCliPath);
|
|
242008
241745
|
const pkgJsonSrc = (0, import_node_path5.join)(distPkgPath, "package.json");
|
|
242009
|
-
|
|
242010
|
-
(0, import_node_fs4.copyFileSync)(pkgJsonSrc, (0, import_node_path5.join)(pkgCliBaseDir, "package.json"));
|
|
242011
|
-
}
|
|
241746
|
+
(0, import_node_fs4.existsSync)(pkgJsonSrc) && (0, import_node_fs4.copyFileSync)(pkgJsonSrc, (0, import_node_path5.join)(pkgCliBaseDir, "package.json"));
|
|
242012
241747
|
const preludeDir = (0, import_node_path5.join)(cacheDir, "pkg-prelude");
|
|
242013
241748
|
(0, import_node_fs4.mkdirSync)(preludeDir, { recursive: true });
|
|
242014
241749
|
for (const file of ["bootstrap.js", "diagnostic.js"]) {
|
|
242015
241750
|
const src = (0, import_node_path5.join)(distPkgPath, "pkg-prelude", file);
|
|
242016
|
-
|
|
242017
|
-
(0, import_node_fs4.copyFileSync)(src, (0, import_node_path5.join)(preludeDir, file));
|
|
242018
|
-
}
|
|
241751
|
+
(0, import_node_fs4.existsSync)(src) && (0, import_node_fs4.copyFileSync)(src, (0, import_node_path5.join)(preludeDir, file));
|
|
242019
241752
|
}
|
|
242020
241753
|
const commonSrc = (0, import_node_path5.join)(distPkgPath, "pkg-common.cjs");
|
|
242021
|
-
|
|
242022
|
-
(0, import_node_fs4.copyFileSync)(commonSrc, (0, import_node_path5.join)(cacheDir, "pkg-common.cjs"));
|
|
242023
|
-
}
|
|
241754
|
+
(0, import_node_fs4.existsSync)(commonSrc) && (0, import_node_fs4.copyFileSync)(commonSrc, (0, import_node_path5.join)(cacheDir, "pkg-common.cjs"));
|
|
242024
241755
|
const dictionaryDir = (0, import_node_path5.join)(pkgCliBaseDir, "dictionary");
|
|
242025
241756
|
(0, import_node_fs4.mkdirSync)(dictionaryDir, { recursive: true });
|
|
242026
241757
|
for (const file of ["v8-7.8.js", "v8-8.4.js", "v8-12.4.js"]) {
|
|
242027
241758
|
const src = (0, import_node_path5.join)(distPkgPath, "pkg-dictionary", file);
|
|
242028
|
-
|
|
242029
|
-
(0, import_node_fs4.copyFileSync)(src, (0, import_node_path5.join)(dictionaryDir, file));
|
|
242030
|
-
}
|
|
241759
|
+
(0, import_node_fs4.existsSync)(src) && (0, import_node_fs4.copyFileSync)(src, (0, import_node_path5.join)(dictionaryDir, file));
|
|
242031
241760
|
}
|
|
242032
241761
|
return pkgCliPath;
|
|
242033
241762
|
}
|
|
@@ -242039,24 +241768,18 @@ function spawnAsync(command, args, options = {}) {
|
|
|
242039
241768
|
env: options.env || process.env,
|
|
242040
241769
|
stdio: options.verbose ? "inherit" : "pipe"
|
|
242041
241770
|
});
|
|
242042
|
-
let stdout = "";
|
|
242043
|
-
|
|
242044
|
-
|
|
242045
|
-
|
|
242046
|
-
|
|
242047
|
-
|
|
242048
|
-
proc.stderr?.on("data", (data) => {
|
|
242049
|
-
stderr += data.toString();
|
|
242050
|
-
});
|
|
242051
|
-
}
|
|
242052
|
-
proc.on("close", (code) => {
|
|
241771
|
+
let stdout = "", stderr = "";
|
|
241772
|
+
options.verbose || (proc.stdout?.on("data", (data) => {
|
|
241773
|
+
stdout += data.toString();
|
|
241774
|
+
}), proc.stderr?.on("data", (data) => {
|
|
241775
|
+
stderr += data.toString();
|
|
241776
|
+
})), proc.on("close", (code) => {
|
|
242053
241777
|
resolve2({
|
|
242054
241778
|
exitCode: code ?? 1,
|
|
242055
241779
|
stdout,
|
|
242056
241780
|
stderr
|
|
242057
241781
|
});
|
|
242058
|
-
})
|
|
242059
|
-
proc.on("error", (error) => {
|
|
241782
|
+
}), proc.on("error", (error) => {
|
|
242060
241783
|
resolve2({
|
|
242061
241784
|
exitCode: 1,
|
|
242062
241785
|
stdout,
|
|
@@ -242067,13 +241790,8 @@ function spawnAsync(command, args, options = {}) {
|
|
|
242067
241790
|
}
|
|
242068
241791
|
__name(spawnAsync, "spawnAsync");
|
|
242069
241792
|
async function compileWithPkgSubprocess(ctx, wrapperPath, target2, outputPath, spinner) {
|
|
242070
|
-
const nodePath = await ensurePortableNode(spinner);
|
|
242071
|
-
|
|
242072
|
-
const pkgTarget = TARGET_MAP[target2];
|
|
242073
|
-
const outputDir = (0, import_node_path5.dirname)(outputPath);
|
|
242074
|
-
if (!(0, import_node_fs4.existsSync)(outputDir)) {
|
|
242075
|
-
(0, import_node_fs4.mkdirSync)(outputDir, { recursive: true });
|
|
242076
|
-
}
|
|
241793
|
+
const nodePath = await ensurePortableNode(spinner), pkgCliPath = ensurePkgCli(), pkgTarget = TARGET_MAP[target2], outputDir = (0, import_node_path5.dirname)(outputPath);
|
|
241794
|
+
(0, import_node_fs4.existsSync)(outputDir) || (0, import_node_fs4.mkdirSync)(outputDir, { recursive: true });
|
|
242077
241795
|
const args = [
|
|
242078
241796
|
pkgCliPath,
|
|
242079
241797
|
wrapperPath,
|
|
@@ -242085,11 +241803,9 @@ async function compileWithPkgSubprocess(ctx, wrapperPath, target2, outputPath, s
|
|
|
242085
241803
|
"experimental-transform-types,disable-warning=ExperimentalWarning",
|
|
242086
241804
|
"--public"
|
|
242087
241805
|
];
|
|
242088
|
-
if (ctx.options.include && ctx.options.include.length > 0)
|
|
242089
|
-
for (const pattern of ctx.options.include)
|
|
241806
|
+
if (ctx.options.include && ctx.options.include.length > 0)
|
|
241807
|
+
for (const pattern of ctx.options.include)
|
|
242090
241808
|
args.push("--assets", pattern);
|
|
242091
|
-
}
|
|
242092
|
-
}
|
|
242093
241809
|
spinner?.start(`Compiling for ${target2}...`);
|
|
242094
241810
|
const result = await spawnAsync(nodePath, args, {
|
|
242095
241811
|
cwd: ctx.buildDir,
|
|
@@ -242115,12 +241831,8 @@ async function compileWithPkg(ctx, wrapperPath, target2, outputPath, spinner) {
|
|
|
242115
241831
|
await compileWithPkgSubprocess(ctx, wrapperPath, target2, outputPath, spinner);
|
|
242116
241832
|
return;
|
|
242117
241833
|
}
|
|
242118
|
-
const { exec } = await import("@yao-pkg/pkg");
|
|
242119
|
-
|
|
242120
|
-
const outputDir = (0, import_node_path5.dirname)(outputPath);
|
|
242121
|
-
if (!(0, import_node_fs4.existsSync)(outputDir)) {
|
|
242122
|
-
(0, import_node_fs4.mkdirSync)(outputDir, { recursive: true });
|
|
242123
|
-
}
|
|
241834
|
+
const { exec } = await import("@yao-pkg/pkg"), pkgTarget = TARGET_MAP[target2], outputDir = (0, import_node_path5.dirname)(outputPath);
|
|
241835
|
+
(0, import_node_fs4.existsSync)(outputDir) || (0, import_node_fs4.mkdirSync)(outputDir, { recursive: true });
|
|
242124
241836
|
const pkgConfig = [
|
|
242125
241837
|
wrapperPath,
|
|
242126
241838
|
"--targets",
|
|
@@ -242132,69 +241844,43 @@ async function compileWithPkg(ctx, wrapperPath, target2, outputPath, spinner) {
|
|
|
242132
241844
|
"--public"
|
|
242133
241845
|
// Include source instead of bytecode (required for cross-compilation)
|
|
242134
241846
|
];
|
|
242135
|
-
if (ctx.options.include && ctx.options.include.length > 0)
|
|
242136
|
-
for (const pattern of ctx.options.include)
|
|
241847
|
+
if (ctx.options.include && ctx.options.include.length > 0)
|
|
241848
|
+
for (const pattern of ctx.options.include)
|
|
242137
241849
|
pkgConfig.push("--assets", pattern);
|
|
242138
|
-
}
|
|
242139
|
-
}
|
|
242140
241850
|
await exec(pkgConfig);
|
|
242141
241851
|
}
|
|
242142
241852
|
__name(compileWithPkg, "compileWithPkg");
|
|
242143
241853
|
function detectTopLevelAwait(filePath) {
|
|
242144
|
-
const
|
|
242145
|
-
|
|
242146
|
-
|
|
242147
|
-
let depth = 0;
|
|
242148
|
-
let inMultiLineComment = false;
|
|
241854
|
+
const lines = (0, import_node_fs4.readFileSync)(filePath, "utf-8").split(`
|
|
241855
|
+
`), awaits = [];
|
|
241856
|
+
let depth = 0, inMultiLineComment = false;
|
|
242149
241857
|
for (let i = 0; i < lines.length; i++) {
|
|
242150
241858
|
let line = lines[i];
|
|
242151
241859
|
if (inMultiLineComment) {
|
|
242152
241860
|
const endIdx = line.indexOf("*/");
|
|
242153
|
-
if (endIdx !== -1)
|
|
242154
|
-
line = line.slice(endIdx + 2);
|
|
242155
|
-
|
|
242156
|
-
} else {
|
|
241861
|
+
if (endIdx !== -1)
|
|
241862
|
+
line = line.slice(endIdx + 2), inMultiLineComment = false;
|
|
241863
|
+
else
|
|
242157
241864
|
continue;
|
|
242158
|
-
}
|
|
242159
241865
|
}
|
|
242160
241866
|
const singleLineCommentIdx = line.indexOf("//");
|
|
242161
|
-
|
|
242162
|
-
line = line.slice(0, singleLineCommentIdx);
|
|
242163
|
-
}
|
|
241867
|
+
singleLineCommentIdx !== -1 && (line = line.slice(0, singleLineCommentIdx));
|
|
242164
241868
|
const multiLineStart = line.indexOf("/*");
|
|
242165
241869
|
if (multiLineStart !== -1) {
|
|
242166
241870
|
const multiLineEnd = line.indexOf("*/", multiLineStart);
|
|
242167
|
-
|
|
242168
|
-
line = line.slice(0, multiLineStart) + line.slice(multiLineEnd + 2);
|
|
242169
|
-
} else {
|
|
242170
|
-
line = line.slice(0, multiLineStart);
|
|
242171
|
-
inMultiLineComment = true;
|
|
242172
|
-
}
|
|
241871
|
+
multiLineEnd !== -1 ? line = line.slice(0, multiLineStart) + line.slice(multiLineEnd + 2) : (line = line.slice(0, multiLineStart), inMultiLineComment = true);
|
|
242173
241872
|
}
|
|
242174
|
-
const openBraces = (line.match(/\{/g) || []).length;
|
|
242175
|
-
|
|
242176
|
-
if (/\b(function|class|async\s+function)\b/.test(line) && line.includes("{")) {
|
|
242177
|
-
depth += 1;
|
|
242178
|
-
} else if (/=>\s*\{/.test(line)) {
|
|
242179
|
-
depth += 1;
|
|
242180
|
-
}
|
|
242181
|
-
depth += openBraces - closeBraces;
|
|
242182
|
-
if (depth < 0)
|
|
242183
|
-
depth = 0;
|
|
242184
|
-
if (depth === 0 && /\bawait\b/.test(line)) {
|
|
241873
|
+
const openBraces = (line.match(/\{/g) || []).length, closeBraces = (line.match(/\}/g) || []).length;
|
|
241874
|
+
if ((/\b(function|class|async\s+function)\b/.test(line) && line.includes("{") || /=>\s*\{/.test(line)) && (depth += 1), depth += openBraces - closeBraces, depth < 0 && (depth = 0), depth === 0 && /\bawait\b/.test(line)) {
|
|
242185
241875
|
const withoutStrings = line.replace(/(["'`])(?:(?!\1)[^\\]|\\.)*\1/g, "");
|
|
242186
|
-
|
|
242187
|
-
awaits.push(i + 1);
|
|
242188
|
-
}
|
|
241876
|
+
/\bawait\b/.test(withoutStrings) && awaits.push(i + 1);
|
|
242189
241877
|
}
|
|
242190
241878
|
}
|
|
242191
241879
|
return awaits;
|
|
242192
241880
|
}
|
|
242193
241881
|
__name(detectTopLevelAwait, "detectTopLevelAwait");
|
|
242194
241882
|
function log(ctx, message) {
|
|
242195
|
-
|
|
242196
|
-
console.log(message);
|
|
242197
|
-
}
|
|
241883
|
+
ctx.options.quiet || console.log(message);
|
|
242198
241884
|
}
|
|
242199
241885
|
__name(log, "log");
|
|
242200
241886
|
function createSpinner(ctx, text) {
|
|
@@ -242205,61 +241891,37 @@ function createSpinner(ctx, text) {
|
|
|
242205
241891
|
}
|
|
242206
241892
|
__name(createSpinner, "createSpinner");
|
|
242207
241893
|
function runDryRun(ctx) {
|
|
242208
|
-
console.log((0, import_node_util2.styleText)("bold",
|
|
242209
|
-
|
|
242210
|
-
|
|
242211
|
-
`);
|
|
242212
|
-
console.log((0, import_node_util2.styleText)("bold", "Targets:"));
|
|
241894
|
+
console.log((0, import_node_util2.styleText)("bold", `Dry run mode - no files will be created
|
|
241895
|
+
`)), console.log((0, import_node_util2.styleText)("bold", "Entry point:")), console.log(` ${ctx.entryPath}
|
|
241896
|
+
`), console.log((0, import_node_util2.styleText)("bold", "Targets:"));
|
|
242213
241897
|
for (const target2 of ctx.resolvedTargets) {
|
|
242214
241898
|
const outputPath = getOutputPath(ctx, target2);
|
|
242215
241899
|
console.log(` ${target2} \u2192 ${outputPath}`);
|
|
242216
241900
|
}
|
|
242217
|
-
console.log()
|
|
242218
|
-
if (ctx.options.include && ctx.options.include.length > 0) {
|
|
241901
|
+
if (console.log(), ctx.options.include && ctx.options.include.length > 0) {
|
|
242219
241902
|
console.log((0, import_node_util2.styleText)("bold", "Assets to include:"));
|
|
242220
|
-
for (const pattern of ctx.options.include)
|
|
241903
|
+
for (const pattern of ctx.options.include)
|
|
242221
241904
|
console.log(` ${pattern}`);
|
|
242222
|
-
}
|
|
242223
241905
|
console.log();
|
|
242224
241906
|
}
|
|
242225
241907
|
if (ctx.options.external && ctx.options.external.length > 0) {
|
|
242226
241908
|
console.log((0, import_node_util2.styleText)("bold", "External packages (not bundled):"));
|
|
242227
|
-
for (const pkg of ctx.options.external)
|
|
241909
|
+
for (const pkg of ctx.options.external)
|
|
242228
241910
|
console.log(` ${pkg}`);
|
|
242229
|
-
}
|
|
242230
241911
|
console.log();
|
|
242231
241912
|
}
|
|
242232
|
-
|
|
242233
|
-
console.log((0, import_node_util2.styleText)("bold", "Minification:"), "enabled");
|
|
242234
|
-
console.log();
|
|
242235
|
-
}
|
|
242236
|
-
console.log((0, import_node_util2.styleText)("bold", "Build steps:"));
|
|
242237
|
-
console.log(" 1. Bundle user script with esbuild");
|
|
242238
|
-
console.log(" 2. Copy thinkwell packages");
|
|
242239
|
-
console.log(" 3. Generate wrapper entry point");
|
|
242240
|
-
console.log(` 4. Compile with pkg for ${ctx.resolvedTargets.length} target(s)`);
|
|
242241
|
-
console.log();
|
|
241913
|
+
ctx.options.minify && (console.log((0, import_node_util2.styleText)("bold", "Minification:"), "enabled"), console.log()), console.log((0, import_node_util2.styleText)("bold", "Build steps:")), console.log(" 1. Bundle user script with esbuild"), console.log(" 2. Copy thinkwell packages"), console.log(" 3. Generate wrapper entry point"), console.log(` 4. Compile with pkg for ${ctx.resolvedTargets.length} target(s)`), console.log();
|
|
242242
241914
|
const topLevelAwaits = detectTopLevelAwait(ctx.entryPath);
|
|
242243
|
-
|
|
242244
|
-
|
|
242245
|
-
console.log(" Top-level await is not supported in compiled binaries.");
|
|
242246
|
-
console.log(` Found at line(s): ${topLevelAwaits.join(", ")}`);
|
|
242247
|
-
console.log(" Wrap async code in an async main() function instead.\n");
|
|
242248
|
-
}
|
|
242249
|
-
console.log((0, import_node_util2.styleText)("dim", "Run without --dry-run to build."));
|
|
241915
|
+
topLevelAwaits.length > 0 && (console.log((0, import_node_util2.styleText)("yellow", "Warning: Top-level await detected")), console.log(" Top-level await is not supported in compiled binaries."), console.log(` Found at line(s): ${topLevelAwaits.join(", ")}`), console.log(` Wrap async code in an async main() function instead.
|
|
241916
|
+
`)), console.log((0, import_node_util2.styleText)("dim", "Run without --dry-run to build."));
|
|
242250
241917
|
}
|
|
242251
241918
|
__name(runDryRun, "runDryRun");
|
|
242252
241919
|
async function runBundle(options) {
|
|
242253
|
-
const entryPath = (0, import_node_path5.isAbsolute)(options.entry) ? options.entry : (0, import_node_path5.resolve)(process.cwd(), options.entry);
|
|
242254
|
-
const projectRoot = findProjectRoot((0, import_node_path5.dirname)(entryPath));
|
|
241920
|
+
const entryPath = (0, import_node_path5.isAbsolute)(options.entry) ? options.entry : (0, import_node_path5.resolve)(process.cwd(), options.entry), projectRoot = findProjectRoot((0, import_node_path5.dirname)(entryPath));
|
|
242255
241921
|
if (projectRoot && (0, import_node_fs4.existsSync)(entryPath)) {
|
|
242256
|
-
const source = (0, import_node_fs4.readFileSync)(entryPath, "utf-8");
|
|
242257
|
-
|
|
242258
|
-
|
|
242259
|
-
if (hasMissingDeps(depCheck, { requireTypescript })) {
|
|
242260
|
-
process.stderr.write(formatMissingDepsError(depCheck, { requireTypescript }) + "\n");
|
|
242261
|
-
process.exit(2);
|
|
242262
|
-
}
|
|
241922
|
+
const source = (0, import_node_fs4.readFileSync)(entryPath, "utf-8"), requireTypescript = hasJsonSchemaMarkers(source), depCheck = await checkDependencies(projectRoot);
|
|
241923
|
+
hasMissingDeps(depCheck, { requireTypescript }) && (process.stderr.write(formatMissingDepsError(depCheck, { requireTypescript }) + `
|
|
241924
|
+
`), process.exit(2));
|
|
242263
241925
|
}
|
|
242264
241926
|
if (options.watch) {
|
|
242265
241927
|
await runWatchMode(options, projectRoot);
|
|
@@ -242268,162 +241930,98 @@ async function runBundle(options) {
|
|
|
242268
241930
|
const ctx = initBundleContext(options);
|
|
242269
241931
|
ctx.projectDir = projectRoot;
|
|
242270
241932
|
const topLevelAwaits = detectTopLevelAwait(ctx.entryPath);
|
|
242271
|
-
if (topLevelAwaits.length > 0) {
|
|
242272
|
-
|
|
242273
|
-
console.log(" Top-level await is not supported in compiled binaries.");
|
|
242274
|
-
console.log(` Found at line(s): ${topLevelAwaits.join(", ")}`);
|
|
242275
|
-
console.log(" Wrap async code in an async main() function instead.\n");
|
|
242276
|
-
}
|
|
242277
|
-
if (options.dryRun) {
|
|
241933
|
+
if (topLevelAwaits.length > 0 && (console.log((0, import_node_util2.styleText)("yellow", "Warning: Top-level await detected")), console.log(" Top-level await is not supported in compiled binaries."), console.log(` Found at line(s): ${topLevelAwaits.join(", ")}`), console.log(` Wrap async code in an async main() function instead.
|
|
241934
|
+
`)), options.dryRun) {
|
|
242278
241935
|
runDryRun(ctx);
|
|
242279
241936
|
return;
|
|
242280
241937
|
}
|
|
242281
241938
|
log(ctx, `Building ${(0, import_node_util2.styleText)("bold", ctx.entryBasename)}...
|
|
242282
|
-
`);
|
|
242283
|
-
if ((0, import_node_fs4.existsSync)(ctx.buildDir)) {
|
|
242284
|
-
(0, import_node_fs4.rmSync)(ctx.buildDir, { recursive: true });
|
|
242285
|
-
}
|
|
242286
|
-
(0, import_node_fs4.mkdirSync)(ctx.buildDir, { recursive: true });
|
|
241939
|
+
`), (0, import_node_fs4.existsSync)(ctx.buildDir) && (0, import_node_fs4.rmSync)(ctx.buildDir, { recursive: true }), (0, import_node_fs4.mkdirSync)(ctx.buildDir, { recursive: true });
|
|
242287
241940
|
try {
|
|
242288
241941
|
let spinner = createSpinner(ctx, "Bundling with esbuild...");
|
|
242289
241942
|
spinner.start();
|
|
242290
241943
|
const userBundlePath = await bundleUserScript(ctx);
|
|
242291
|
-
spinner.succeed("User script bundled");
|
|
242292
|
-
|
|
242293
|
-
|
|
242294
|
-
copyThinkwellBundles(ctx);
|
|
242295
|
-
spinner.succeed("Thinkwell packages ready");
|
|
242296
|
-
const wrapperPath = (0, import_node_path5.join)(ctx.buildDir, "wrapper.cjs");
|
|
242297
|
-
const wrapperSource = generateWrapperSource(userBundlePath);
|
|
242298
|
-
(0, import_node_fs4.writeFileSync)(wrapperPath, wrapperSource);
|
|
242299
|
-
if (ctx.options.verbose) {
|
|
242300
|
-
log(ctx, " Generated wrapper entry point");
|
|
242301
|
-
}
|
|
241944
|
+
spinner.succeed("User script bundled"), spinner = createSpinner(ctx, "Preparing thinkwell packages..."), spinner.start(), copyThinkwellBundles(ctx), spinner.succeed("Thinkwell packages ready");
|
|
241945
|
+
const wrapperPath = (0, import_node_path5.join)(ctx.buildDir, "wrapper.cjs"), wrapperSource = generateWrapperSource(userBundlePath);
|
|
241946
|
+
(0, import_node_fs4.writeFileSync)(wrapperPath, wrapperSource), ctx.options.verbose && log(ctx, " Generated wrapper entry point");
|
|
242302
241947
|
const outputs = [];
|
|
242303
241948
|
for (const target2 of ctx.resolvedTargets) {
|
|
242304
241949
|
const outputPath = getOutputPath(ctx, target2);
|
|
242305
|
-
spinner = createSpinner(ctx, `Compiling for ${target2}...`);
|
|
242306
|
-
spinner.start();
|
|
242307
|
-
await compileWithPkg(ctx, wrapperPath, target2, outputPath, spinner);
|
|
242308
|
-
outputs.push(outputPath);
|
|
242309
|
-
spinner.succeed(`Built ${(0, import_node_path5.basename)(outputPath)}`);
|
|
241950
|
+
spinner = createSpinner(ctx, `Compiling for ${target2}...`), spinner.start(), await compileWithPkg(ctx, wrapperPath, target2, outputPath, spinner), outputs.push(outputPath), spinner.succeed(`Built ${(0, import_node_path5.basename)(outputPath)}`);
|
|
242310
241951
|
}
|
|
242311
|
-
log(ctx, "");
|
|
242312
|
-
|
|
242313
|
-
log(ctx, "");
|
|
242314
|
-
log(ctx, (0, import_node_util2.styleText)("bold", "Output:"));
|
|
242315
|
-
for (const output of outputs) {
|
|
241952
|
+
log(ctx, ""), log(ctx, (0, import_node_util2.styleText)("green", "Build complete!")), log(ctx, ""), log(ctx, (0, import_node_util2.styleText)("bold", "Output:"));
|
|
241953
|
+
for (const output of outputs)
|
|
242316
241954
|
log(ctx, ` ${output}`);
|
|
242317
|
-
}
|
|
242318
241955
|
} finally {
|
|
242319
|
-
if (
|
|
241956
|
+
if (ctx.options.verbose)
|
|
241957
|
+
log(ctx, `
|
|
241958
|
+
Build artifacts preserved in: ${ctx.buildDir}`);
|
|
241959
|
+
else
|
|
242320
241960
|
try {
|
|
242321
241961
|
(0, import_node_fs4.rmSync)(ctx.buildDir, { recursive: true });
|
|
242322
241962
|
} catch {
|
|
242323
241963
|
}
|
|
242324
|
-
} else {
|
|
242325
|
-
log(ctx, `
|
|
242326
|
-
Build artifacts preserved in: ${ctx.buildDir}`);
|
|
242327
|
-
}
|
|
242328
241964
|
}
|
|
242329
241965
|
}
|
|
242330
241966
|
__name(runBundle, "runBundle");
|
|
242331
241967
|
async function runWatchMode(options, projectDir) {
|
|
242332
241968
|
const ctx = initBundleContext(options);
|
|
242333
|
-
ctx.projectDir = projectDir
|
|
242334
|
-
|
|
242335
|
-
|
|
242336
|
-
let buildInProgress = false;
|
|
242337
|
-
let rebuildQueued = false;
|
|
242338
|
-
let debounceTimer = null;
|
|
241969
|
+
ctx.projectDir = projectDir, console.log((0, import_node_util2.styleText)("bold", `Watching ${ctx.entryBasename} for changes...`)), console.log((0, import_node_util2.styleText)("dim", `Press Ctrl+C to stop.
|
|
241970
|
+
`));
|
|
241971
|
+
let buildInProgress = false, rebuildQueued = false, debounceTimer = null;
|
|
242339
241972
|
const DEBOUNCE_MS = 100;
|
|
242340
241973
|
async function doBuild() {
|
|
242341
241974
|
if (buildInProgress) {
|
|
242342
241975
|
rebuildQueued = true;
|
|
242343
241976
|
return;
|
|
242344
241977
|
}
|
|
242345
|
-
buildInProgress = true;
|
|
242346
|
-
rebuildQueued = false;
|
|
241978
|
+
buildInProgress = true, rebuildQueued = false;
|
|
242347
241979
|
const startTime = Date.now();
|
|
242348
241980
|
console.log((0, import_node_util2.styleText)("dim", `[${(/* @__PURE__ */ new Date()).toLocaleTimeString()}] Building...`));
|
|
242349
241981
|
try {
|
|
242350
241982
|
const freshCtx = initBundleContext(options);
|
|
242351
|
-
|
|
242352
|
-
(0, import_node_fs4.rmSync)(freshCtx.buildDir, { recursive: true });
|
|
242353
|
-
}
|
|
242354
|
-
(0, import_node_fs4.mkdirSync)(freshCtx.buildDir, { recursive: true });
|
|
241983
|
+
(0, import_node_fs4.existsSync)(freshCtx.buildDir) && (0, import_node_fs4.rmSync)(freshCtx.buildDir, { recursive: true }), (0, import_node_fs4.mkdirSync)(freshCtx.buildDir, { recursive: true });
|
|
242355
241984
|
const userBundlePath = await bundleUserScript(freshCtx);
|
|
242356
241985
|
copyThinkwellBundles(freshCtx);
|
|
242357
|
-
const wrapperPath = (0, import_node_path5.join)(freshCtx.buildDir, "wrapper.cjs");
|
|
242358
|
-
const wrapperSource = generateWrapperSource(userBundlePath);
|
|
241986
|
+
const wrapperPath = (0, import_node_path5.join)(freshCtx.buildDir, "wrapper.cjs"), wrapperSource = generateWrapperSource(userBundlePath);
|
|
242359
241987
|
(0, import_node_fs4.writeFileSync)(wrapperPath, wrapperSource);
|
|
242360
241988
|
const outputs = [];
|
|
242361
241989
|
for (const target2 of freshCtx.resolvedTargets) {
|
|
242362
241990
|
const outputPath = getOutputPath(freshCtx, target2);
|
|
242363
|
-
await compileWithPkg(freshCtx, wrapperPath, target2, outputPath);
|
|
242364
|
-
outputs.push(outputPath);
|
|
241991
|
+
await compileWithPkg(freshCtx, wrapperPath, target2, outputPath), outputs.push(outputPath);
|
|
242365
241992
|
}
|
|
242366
|
-
if (!freshCtx.options.verbose)
|
|
241993
|
+
if (!freshCtx.options.verbose)
|
|
242367
241994
|
try {
|
|
242368
241995
|
(0, import_node_fs4.rmSync)(freshCtx.buildDir, { recursive: true });
|
|
242369
241996
|
} catch {
|
|
242370
241997
|
}
|
|
242371
|
-
}
|
|
242372
241998
|
const elapsed = Date.now() - startTime;
|
|
242373
241999
|
console.log((0, import_node_util2.styleText)("green", `\u2713 Built in ${elapsed}ms`));
|
|
242374
|
-
for (const output of outputs)
|
|
242000
|
+
for (const output of outputs)
|
|
242375
242001
|
console.log((0, import_node_util2.styleText)("dim", ` ${(0, import_node_path5.basename)(output)}`));
|
|
242376
|
-
}
|
|
242377
242002
|
console.log();
|
|
242378
242003
|
} catch (error) {
|
|
242379
242004
|
const message = error instanceof Error ? error.message : String(error);
|
|
242380
|
-
console.log((0, import_node_util2.styleText)("red", `\u2717 Build failed: ${message}`));
|
|
242381
|
-
console.log();
|
|
242005
|
+
console.log((0, import_node_util2.styleText)("red", `\u2717 Build failed: ${message}`)), console.log();
|
|
242382
242006
|
} finally {
|
|
242383
|
-
buildInProgress = false;
|
|
242384
|
-
if (rebuildQueued) {
|
|
242385
|
-
doBuild();
|
|
242386
|
-
}
|
|
242007
|
+
buildInProgress = false, rebuildQueued && doBuild();
|
|
242387
242008
|
}
|
|
242388
242009
|
}
|
|
242389
242010
|
__name(doBuild, "doBuild");
|
|
242390
242011
|
function scheduleRebuild() {
|
|
242391
|
-
|
|
242392
|
-
|
|
242393
|
-
}
|
|
242394
|
-
debounceTimer = setTimeout(() => {
|
|
242395
|
-
debounceTimer = null;
|
|
242396
|
-
doBuild();
|
|
242012
|
+
debounceTimer && clearTimeout(debounceTimer), debounceTimer = setTimeout(() => {
|
|
242013
|
+
debounceTimer = null, doBuild();
|
|
242397
242014
|
}, DEBOUNCE_MS);
|
|
242398
242015
|
}
|
|
242399
242016
|
__name(scheduleRebuild, "scheduleRebuild");
|
|
242400
242017
|
await doBuild();
|
|
242401
|
-
const watchDir = ctx.entryDir
|
|
242402
|
-
|
|
242403
|
-
|
|
242404
|
-
|
|
242405
|
-
|
|
242406
|
-
return;
|
|
242407
|
-
}
|
|
242408
|
-
if (!/\.(ts|tsx|js|jsx|mts|mjs|cts|cjs|json)$/.test(filename)) {
|
|
242409
|
-
return;
|
|
242410
|
-
}
|
|
242411
|
-
if (ctx.options.verbose) {
|
|
242412
|
-
console.log((0, import_node_util2.styleText)("dim", ` Changed: ${filename}`));
|
|
242413
|
-
}
|
|
242414
|
-
scheduleRebuild();
|
|
242415
|
-
});
|
|
242416
|
-
const cleanup = /* @__PURE__ */ __name(() => {
|
|
242417
|
-
watcher.close();
|
|
242418
|
-
if (debounceTimer) {
|
|
242419
|
-
clearTimeout(debounceTimer);
|
|
242420
|
-
}
|
|
242421
|
-
console.log("\nStopped watching.");
|
|
242422
|
-
process.exit(0);
|
|
242018
|
+
const watchDir = ctx.entryDir, watcher = (0, import_node_fs4.watch)(watchDir, { recursive: true }, (_eventType, filename) => {
|
|
242019
|
+
filename && (filename.includes("node_modules") || filename.startsWith(".") || filename.endsWith(".d.ts") || /\.(ts|tsx|js|jsx|mts|mjs|cts|cjs|json)$/.test(filename) && (ctx.options.verbose && console.log((0, import_node_util2.styleText)("dim", ` Changed: ${filename}`)), scheduleRebuild()));
|
|
242020
|
+
}), cleanup = /* @__PURE__ */ __name(() => {
|
|
242021
|
+
watcher.close(), debounceTimer && clearTimeout(debounceTimer), console.log(`
|
|
242022
|
+
Stopped watching.`), process.exit(0);
|
|
242423
242023
|
}, "cleanup");
|
|
242424
|
-
process.on("SIGINT", cleanup)
|
|
242425
|
-
process.on("SIGTERM", cleanup);
|
|
242426
|
-
await new Promise(() => {
|
|
242024
|
+
process.on("SIGINT", cleanup), process.on("SIGTERM", cleanup), await new Promise(() => {
|
|
242427
242025
|
});
|
|
242428
242026
|
}
|
|
242429
242027
|
__name(runWatchMode, "runWatchMode");
|
|
@@ -242489,7 +242087,8 @@ ${greenBold("Configuration via package.json:")}
|
|
|
242489
242087
|
|
|
242490
242088
|
${dim("Note: Binaries are ~70-90 MB due to the embedded Node.js runtime.")}
|
|
242491
242089
|
${dim(" Use --minify to reduce bundle size (though Node.js runtime dominates).")}
|
|
242492
|
-
`.trim() +
|
|
242090
|
+
`.trim() + `
|
|
242091
|
+
`);
|
|
242493
242092
|
}
|
|
242494
242093
|
__name(showBundleHelp, "showBundleHelp");
|
|
242495
242094
|
// Annotate the CommonJS export names for ESM import in node:
|