The errors package is now importable
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
build/
|
||||
node_modules/
|
||||
package-lock.json
|
||||
pnpm-lock.yaml
|
||||
7
experiments/package.json
Normal file
7
experiments/package.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"name": "experiments",
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"@efforting.tech/errors": "link:../build/packages/errors"
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
|
||||
import { Item_Unresolvable } from '@efforting.tech/errors';
|
||||
|
||||
|
||||
class Abstract_Resolver {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
scope: '@efforting.tech'
|
||||
|
||||
|
||||
packages:
|
||||
errors:
|
||||
path: source/errors.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']
|
||||
|
||||
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');
|
||||
|
||||
Reference in New Issue
Block a user