From 443dda6717e47c8bde8a2a4b747d59765e06b7e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikael=20L=C3=B6vqvist?= Date: Sat, 4 Apr 2026 09:36:51 +0200 Subject: [PATCH] The errors package is now importable --- .gitignore | 3 ++- experiments/package.json | 7 +++++++ experiments/res1.mjs | 2 +- package-manifest.yaml | 1 + tools/stage-for-pnpn.mjs | 41 ++++++++++++++++++++++++++++++++++------ 5 files changed, 46 insertions(+), 8 deletions(-) create mode 100644 experiments/package.json diff --git a/.gitignore b/.gitignore index 85191cc..9bf9f09 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ build/ node_modules/ -package-lock.json \ No newline at end of file +package-lock.json +pnpm-lock.yaml \ No newline at end of file diff --git a/experiments/package.json b/experiments/package.json new file mode 100644 index 0000000..90ec16a --- /dev/null +++ b/experiments/package.json @@ -0,0 +1,7 @@ +{ + "name": "experiments", + "type": "module", + "dependencies": { + "@efforting.tech/errors": "link:../build/packages/errors" + } +} \ No newline at end of file diff --git a/experiments/res1.mjs b/experiments/res1.mjs index df90ae9..609fa8d 100644 --- a/experiments/res1.mjs +++ b/experiments/res1.mjs @@ -1,4 +1,4 @@ - +import { Item_Unresolvable } from '@efforting.tech/errors'; class Abstract_Resolver { diff --git a/package-manifest.yaml b/package-manifest.yaml index 3ce591d..07e6de4 100644 --- a/package-manifest.yaml +++ b/package-manifest.yaml @@ -1,5 +1,6 @@ scope: '@efforting.tech' + packages: errors: path: source/errors.mjs diff --git a/tools/stage-for-pnpn.mjs b/tools/stage-for-pnpn.mjs index e417ce7..8d0b171 100644 --- a/tools/stage-for-pnpn.mjs +++ b/tools/stage-for-pnpn.mjs @@ -1,10 +1,11 @@ -import { parse as parse_yaml } from 'yaml'; -import { readFileSync, readdirSync, mkdirSync, symlinkSync, statSync, readlinkSync } from 'node:fs'; +import { parse as parse_yaml, stringify as format_yaml } from 'yaml'; +import { readFileSync, writeFileSync, readdirSync, mkdirSync, symlinkSync, statSync, readlinkSync } from 'node:fs'; import path from 'node:path'; const [manifest_file, source, output_directory] = process.argv.slice(2); const manifest = parse_yaml(readFileSync(manifest_file, 'utf-8')); +//TODO: We must test this with a non-single-file type package //NOTE: For now we will simply symlink files over from source which is fine as long as we are @@ -49,23 +50,51 @@ function symlink_tree(src, dest) { } +const workspace_manifest = { + packages: [], +}; +const root_package = { + name: path.join(manifest.scope, 'root'), + version: '0.1.0', //TODO: Not hardcode? What does this version even represent? + type: 'module', + dependencies: {}, +}; for (const [package_name, package_data] of Object.entries(manifest.packages)) { const pkg = { name: package_name, ...package_data }; + const pkg_scope_path = path.join(manifest.scope, pkg.name); + workspace_manifest.packages.push(pkg.name); + const pkg_dir = path.join(output_directory, pkg.name); const symlinked_files = symlink_tree(pkg.path, pkg_dir).map(p => path.relative(pkg_dir, p)); + const exports_map = {}; + for (const file of symlinked_files) { + const name = path.basename(file, '.mjs'); + const key = name === pkg.name ? '.' : `./${name}`; + exports_map[key] = `./${file}`; + } + const { version, description } = pkg; const pkg_json = JSON.stringify({ - name: path.join(manifest.scope, pkg.name), + name: pkg_scope_path, version, description, type: 'module', + exports: exports_map, }, null, ' '); - console.log(pkg_json); - console.log({symlinked_files}); // ['errors.mjs'] + writeFileSync(path.join(pkg_dir, 'package.json'), pkg_json, 'utf-8'); + //console.log({symlinked_files}); // ['errors.mjs'] -} \ No newline at end of file + root_package.dependencies[pkg_scope_path] = 'workspace:*'; + +} + +const root_pkg_json = JSON.stringify(root_package, null, ' '); +writeFileSync(path.join(output_directory, 'package.json'), root_pkg_json, 'utf-8'); + + +writeFileSync(path.join(output_directory, 'pnpm-workspace.yaml'), format_yaml(workspace_manifest), 'utf-8');