@inlang/paraglide-js 2.29.0 → 2.29.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -39,6 +39,18 @@ export async function compile(options) {
39
39
  });
40
40
  let failed = false;
41
41
  try {
42
+ // Missing files are skipped by the SDK, but unreadable ones would
43
+ // compile into incomplete output that replaces the previous one.
44
+ // The SDK does not export ResourceFileImportError, so match by name.
45
+ const resourceFileErrors = (await project.errors.get()).filter((error) => error.name === "ResourceFileImportError");
46
+ if (resourceFileErrors.length > 0) {
47
+ const failures = resourceFileErrors.map((error) => {
48
+ const { path: file } = error;
49
+ const cause = error.cause;
50
+ return `${file} (${cause?.code ?? String(error.cause)})`;
51
+ });
52
+ throw new AggregateError(resourceFileErrors, `Failed to read translation resource files: ${failures.join(", ")}`);
53
+ }
42
54
  const output = await compileProject({
43
55
  compilerOptions: withDefaultOptions,
44
56
  project,
@@ -1 +1 @@
1
- {"version":3,"file":"compile.js","sourceRoot":"","sources":["../../src/compiler/compile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,2CAA2C,CAAC;AACxE,OAAO,EACN,sBAAsB,GAEtB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AAErD,uFAAuF;AACvF,kFAAkF;AAClF,IAAI,qBAAqB,GAEb,IAAI,CAAC;AAMjB,MAAM,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;AAE5B;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAC5B,OAEC;IAED,MAAM,kBAAkB,GAAG;QAC1B,GAAG,sBAAsB;QACzB,GAAG,OAAO;KACV,CAAC;IAEF,IA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ACV,IAAI,CAAC;oBACJ,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;gBACvB,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBAChB,yDAAyD;oBACzD,6CAA6C;oBAC7C,IAAI,CAAC,MAAM;wBAAE,MAAM,KAAK,CAAC;oBACzB,iEAAiE;oBACjE,MAAM,CAAC,IAAI,CAAC,0BAA0B,EAAE,KAAK,CAAC,CAAC;gBAChD,CAAC;YACF,CAAC;QACF,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACZ,uCAAuC;YACvC,qBAAqB,GAAG,IAAI,CAAC;YAC7B,MAAM,CAAC,CAAC;QACT,CAAC;IACF,CAAC,CAAC,EAAE,CAAC;IAEL,MAAM,MAAM,GAAG,eAAe,CAAC,MAAM,qBAAqB,CAAC,CAAC;IAC5D,qBAAqB,GAAG,IAAI,CAAC;IAE7B,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["import { loadProjectFromDirectory } from \"@inlang/sdk\";\nimport path from \"node:path\";\nimport { compileProject } from \"./compile-project.js\";\nimport { writeOutput } from \"../services/file-handling/write-output.js\";\nimport {\n\tdefaultCompilerOptions,\n\ttype CompilerOptions,\n} from \"./compiler-options.js\";\nimport { Logger } from \"../services/logger/index.js\";\n\n// This is a workaround to prevent multiple compilations from running at the same time.\n// https://github.com/opral/inlang-paraglide-js/issues/320#issuecomment-2596951222\nlet compilationInProgress: Promise<{\n\toutputHashes: Record<string, string> | undefined;\n}> | null = null;\n\nexport type CompilationResult = {\n\toutputHashes: Record<string, string> | undefined;\n};\n\nconst logger = new Logger();\n\n/**\n * Loads, compiles, and writes the output to disk.\n *\n * This is the main function to use when you want to compile a project.\n * If you want to adjust inlang project loading, or the output, use\n * `compileProject()` instead.\n *\n * @example\n * await compile({\n * project: 'path/to/project',\n * outdir: 'path/to/output',\n * })\n */\nexport async function compile(\n\toptions: CompilerOptions & {\n\t\tpreviousCompilation?: CompilationResult;\n\t}\n): Promise<CompilationResult> {\n\tconst withDefaultOptions = {\n\t\t...defaultCompilerOptions,\n\t\t...options,\n\t};\n\n\tif (compilationInProgress) {\n\t\tawait compilationInProgress;\n\t}\n\n\tcompilationInProgress = (async () => {\n\t\ttry {\n\t\t\tconst fs = withDefaultOptions.fs ?? (await import(\"node:fs\"));\n\t\t\tconst absoluteOutdir = path.resolve(\n\t\t\t\tprocess.cwd(),\n\t\t\t\twithDefaultOptions.outdir\n\t\t\t);\n\n\t\t\tconst project = await loadProjectFromDirectory({\n\t\t\t\tpath: withDefaultOptions.project,\n\t\t\t\tfs,\n\t\t\t});\n\n\t\t\tlet failed = false;\n\t\t\ttry {\n\t\t\t\tconst output = await compileProject({\n\t\t\t\t\tcompilerOptions: withDefaultOptions,\n\t\t\t\t\tproject,\n\t\t\t\t\tprojectPath: withDefaultOptions.project,\n\t\t\t\t});\n\n\t\t\t\tconst outputHashes = await writeOutput({\n\t\t\t\t\tdirectory: absoluteOutdir,\n\t\t\t\t\toutput,\n\t\t\t\t\tcleanDirectory: withDefaultOptions.cleanOutdir,\n\t\t\t\t\tfs: fs.promises,\n\t\t\t\t\tpreviousOutputHashes: options.previousCompilation?.outputHashes,\n\t\t\t\t});\n\n\t\t\t\tconst warningsAndErrors = await project.errors.get();\n\n\t\t\t\tfor (const warningOrError of warningsAndErrors) {\n\t\t\t\t\tlogger.warn(warningOrError);\n\t\t\t\t}\n\n\t\t\t\treturn { outputHashes };\n\t\t\t} catch (error) {\n\t\t\t\tfailed = true;\n\t\t\t\tthrow error;\n\t\t\t} finally {\n\t\t\t\ttry {\n\t\t\t\t\tawait project.close();\n\t\t\t\t} catch (error) {\n\t\t\t\t\t// Closing must fail an otherwise successful compilation.\n\t\t\t\t\t// eslint-disable-next-line no-unsafe-finally\n\t\t\t\t\tif (!failed) throw error;\n\t\t\t\t\t// Keep the actionable compile/write error if cleanup also fails.\n\t\t\t\t\tlogger.warn(\"Failed to close project:\", error);\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (e) {\n\t\t\t// release the lock in case of an error\n\t\t\tcompilationInProgress = null;\n\t\t\tthrow e;\n\t\t}\n\t})();\n\n\tconst result = structuredClone(await compilationInProgress);\n\tcompilationInProgress = null;\n\n\treturn result;\n}\n"]}
1
+ {"version":3,"file":"compile.js","sourceRoot":"","sources":["../../src/compiler/compile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,2CAA2C,CAAC;AACxE,OAAO,EACN,sBAAsB,GAEtB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AAErD,uFAAuF;AACvF,kFAAkF;AAClF,IAAI,qBAAqB,GAEb,IAAI,CAAC;AAMjB,MAAM,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;AAE5B;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAC5B,OAEC;IAED,MAAM,kBAAkB,GAAG;QAC1B,GAAG,sBAAsB;QACzB,GAAG,OAAO;KACV,CAAC;IAEF,IAAI,qBAAqB,EAAE,CAAC;QAC3B,MAAM,qBAAqB,CAAC;IAC7B,CAAC;IAED,qBAAqB,GAAG,CAAC,KAAK,IAAI,EAAE;QACnC,IAAI,CAAC;YACJ,MAAM,EAAE,GAAG,kBAAkB,CAAC,EAAE,IAAI,CAAC,MAAM,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC;YAC9D,MAAM,cAAc,GAAG,IAAI,CAAC,OAAO,CAClC,OAAO,CAAC,GAAG,EAAE,EACb,kBAAkB,CAAC,MAAM,CACzB,CAAC;YAEF,MAAM,OAAO,GAAG,MAAM,wBAAwB,CAAC;gBAC9C,IAAI,EAAE,kBAAkB,CAAC,OAAO;gBAChC,EAAE;aACF,CAAC,CAAC;YAEH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K,MAAM,cAAc,IAAI,iBAAiB,EAAE,CAAC;oBAChD,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;gBAC7B,CAAC;gBAED,OAAO,EAAE,YAAY,EAAE,CAAC;YACzB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBAChB,MAAM,GAAG,IAAI,CAAC;gBACd,MAAM,KAAK,CAAC;YACb,CAAC;oBAAS,CAAC;gBACV,IAAI,CAAC;oBACJ,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;gBACvB,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBAChB,yDAAyD;oBACzD,6CAA6C;oBAC7C,IAAI,CAAC,MAAM;wBAAE,MAAM,KAAK,CAAC;oBACzB,iEAAiE;oBACjE,MAAM,CAAC,IAAI,CAAC,0BAA0B,EAAE,KAAK,CAAC,CAAC;gBAChD,CAAC;YACF,CAAC;QACF,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACZ,uCAAuC;YACvC,qBAAqB,GAAG,IAAI,CAAC;YAC7B,MAAM,CAAC,CAAC;QACT,CAAC;IACF,CAAC,CAAC,EAAE,CAAC;IAEL,MAAM,MAAM,GAAG,eAAe,CAAC,MAAM,qBAAqB,CAAC,CAAC;IAC5D,qBAAqB,GAAG,IAAI,CAAC;IAE7B,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["import { loadProjectFromDirectory } from \"@inlang/sdk\";\nimport path from \"node:path\";\nimport { compileProject } from \"./compile-project.js\";\nimport { writeOutput } from \"../services/file-handling/write-output.js\";\nimport {\n\tdefaultCompilerOptions,\n\ttype CompilerOptions,\n} from \"./compiler-options.js\";\nimport { Logger } from \"../services/logger/index.js\";\n\n// This is a workaround to prevent multiple compilations from running at the same time.\n// https://github.com/opral/inlang-paraglide-js/issues/320#issuecomment-2596951222\nlet compilationInProgress: Promise<{\n\toutputHashes: Record<string, string> | undefined;\n}> | null = null;\n\nexport type CompilationResult = {\n\toutputHashes: Record<string, string> | undefined;\n};\n\nconst logger = new Logger();\n\n/**\n * Loads, compiles, and writes the output to disk.\n *\n * This is the main function to use when you want to compile a project.\n * If you want to adjust inlang project loading, or the output, use\n * `compileProject()` instead.\n *\n * @example\n * await compile({\n * project: 'path/to/project',\n * outdir: 'path/to/output',\n * })\n */\nexport async function compile(\n\toptions: CompilerOptions & {\n\t\tpreviousCompilation?: CompilationResult;\n\t}\n): Promise<CompilationResult> {\n\tconst withDefaultOptions = {\n\t\t...defaultCompilerOptions,\n\t\t...options,\n\t};\n\n\tif (compilationInProgress) {\n\t\tawait compilationInProgress;\n\t}\n\n\tcompilationInProgress = (async () => {\n\t\ttry {\n\t\t\tconst fs = withDefaultOptions.fs ?? (await import(\"node:fs\"));\n\t\t\tconst absoluteOutdir = path.resolve(\n\t\t\t\tprocess.cwd(),\n\t\t\t\twithDefaultOptions.outdir\n\t\t\t);\n\n\t\t\tconst project = await loadProjectFromDirectory({\n\t\t\t\tpath: withDefaultOptions.project,\n\t\t\t\tfs,\n\t\t\t});\n\n\t\t\tlet failed = false;\n\t\t\ttry {\n\t\t\t\t// Missing files are skipped by the SDK, but unreadable ones would\n\t\t\t\t// compile into incomplete output that replaces the previous one.\n\t\t\t\t// The SDK does not export ResourceFileImportError, so match by name.\n\t\t\t\tconst resourceFileErrors = (await project.errors.get()).filter(\n\t\t\t\t\t(error) => error.name === \"ResourceFileImportError\"\n\t\t\t\t);\n\t\t\t\tif (resourceFileErrors.length > 0) {\n\t\t\t\t\tconst failures = resourceFileErrors.map((error) => {\n\t\t\t\t\t\tconst { path: file } = error as Error & { path?: string };\n\t\t\t\t\t\tconst cause = error.cause as { code?: string } | undefined;\n\t\t\t\t\t\treturn `${file} (${cause?.code ?? String(error.cause)})`;\n\t\t\t\t\t});\n\t\t\t\t\tthrow new AggregateError(\n\t\t\t\t\t\tresourceFileErrors,\n\t\t\t\t\t\t`Failed to read translation resource files: ${failures.join(\", \")}`\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tconst output = await compileProject({\n\t\t\t\t\tcompilerOptions: withDefaultOptions,\n\t\t\t\t\tproject,\n\t\t\t\t\tprojectPath: withDefaultOptions.project,\n\t\t\t\t});\n\n\t\t\t\tconst outputHashes = await writeOutput({\n\t\t\t\t\tdirectory: absoluteOutdir,\n\t\t\t\t\toutput,\n\t\t\t\t\tcleanDirectory: withDefaultOptions.cleanOutdir,\n\t\t\t\t\tfs: fs.promises,\n\t\t\t\t\tpreviousOutputHashes: options.previousCompilation?.outputHashes,\n\t\t\t\t});\n\n\t\t\t\tconst warningsAndErrors = await project.errors.get();\n\n\t\t\t\tfor (const warningOrError of warningsAndErrors) {\n\t\t\t\t\tlogger.warn(warningOrError);\n\t\t\t\t}\n\n\t\t\t\treturn { outputHashes };\n\t\t\t} catch (error) {\n\t\t\t\tfailed = true;\n\t\t\t\tthrow error;\n\t\t\t} finally {\n\t\t\t\ttry {\n\t\t\t\t\tawait project.close();\n\t\t\t\t} catch (error) {\n\t\t\t\t\t// Closing must fail an otherwise successful compilation.\n\t\t\t\t\t// eslint-disable-next-line no-unsafe-finally\n\t\t\t\t\tif (!failed) throw error;\n\t\t\t\t\t// Keep the actionable compile/write error if cleanup also fails.\n\t\t\t\t\tlogger.warn(\"Failed to close project:\", error);\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (e) {\n\t\t\t// release the lock in case of an error\n\t\t\tcompilationInProgress = null;\n\t\t\tthrow e;\n\t\t}\n\t})();\n\n\tconst result = structuredClone(await compilationInProgress);\n\tcompilationInProgress = null;\n\n\treturn result;\n}\n"]}
@@ -1,4 +1,4 @@
1
1
  export const ENV_VARIABLES = {
2
- PARJS_PACKAGE_VERSION: "2.29.0",
2
+ PARJS_PACKAGE_VERSION: "2.29.1",
3
3
  };
4
4
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/services/env-variables/index.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,MAAM,aAAa,GAAG;IAC5B,qBAAqB,EAAE,QAAQ;CAC/B,CAAA","sourcesContent":["\nexport const ENV_VARIABLES = {\n\tPARJS_PACKAGE_VERSION: \"2.29.0\",\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/services/env-variables/index.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,MAAM,aAAa,GAAG;IAC5B,qBAAqB,EAAE,QAAQ;CAC/B,CAAA","sourcesContent":["\nexport const ENV_VARIABLES = {\n\tPARJS_PACKAGE_VERSION: \"2.29.1\",\n}\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@inlang/paraglide-js",
3
3
  "type": "module",
4
- "version": "2.29.0",
4
+ "version": "2.29.1",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
7
7
  "access": "public",