The errors package is now importable

This commit is contained in:
2026-04-04 09:36:51 +02:00
parent 9b58aee54c
commit 443dda6717
5 changed files with 46 additions and 8 deletions

1
.gitignore vendored
View File

@@ -1,3 +1,4 @@
build/ build/
node_modules/ node_modules/
package-lock.json package-lock.json
pnpm-lock.yaml

7
experiments/package.json Normal file
View File

@@ -0,0 +1,7 @@
{
"name": "experiments",
"type": "module",
"dependencies": {
"@efforting.tech/errors": "link:../build/packages/errors"
}
}

View File

@@ -1,4 +1,4 @@
import { Item_Unresolvable } from '@efforting.tech/errors';
class Abstract_Resolver { class Abstract_Resolver {

View File

@@ -1,5 +1,6 @@
scope: '@efforting.tech' scope: '@efforting.tech'
packages: packages:
errors: errors:
path: source/errors.mjs path: source/errors.mjs

View File

@@ -1,10 +1,11 @@
import { parse as parse_yaml } from 'yaml'; import { parse as parse_yaml, stringify as format_yaml } from 'yaml';
import { readFileSync, readdirSync, mkdirSync, symlinkSync, statSync, readlinkSync } from 'node:fs'; import { readFileSync, writeFileSync, readdirSync, mkdirSync, symlinkSync, statSync, readlinkSync } from 'node:fs';
import path from 'node:path'; import path from 'node:path';
const [manifest_file, source, output_directory] = process.argv.slice(2); const [manifest_file, source, output_directory] = process.argv.slice(2);
const manifest = parse_yaml(readFileSync(manifest_file, 'utf-8')); 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 //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)) { for (const [package_name, package_data] of Object.entries(manifest.packages)) {
const pkg = { name: package_name, ...package_data }; 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 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 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 { version, description } = pkg;
const pkg_json = JSON.stringify({ const pkg_json = JSON.stringify({
name: path.join(manifest.scope, pkg.name), name: pkg_scope_path,
version, description, version, description,
type: 'module', type: 'module',
exports: exports_map,
}, null, ' '); }, null, ' ');
console.log(pkg_json); writeFileSync(path.join(pkg_dir, 'package.json'), pkg_json, 'utf-8');
console.log({symlinked_files}); // ['errors.mjs'] //console.log({symlinked_files}); // ['errors.mjs']
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');