@decohere/workspace 0.0.1-dev.130 → 0.0.1-dev.20261105.103

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/README.md CHANGED
@@ -56,6 +56,8 @@ For each discovered project, the workspace package maps `package.json` `name` to
56
56
 
57
57
  Root `tsconfig.json` `paths` override the same keys. In this repo they come from `forge paths`, which writes this map to `tsconfig.paths.json` for `tsc`.
58
58
 
59
+ `tsconfig.json` is read with [get-tsconfig](https://github.com/privatenumber/get-tsconfig), which follows `extends`, not with the TypeScript compiler: loading the compiler takes longer than the rest of a `flux run`. Transpiling uses only `paths` and `baseUrl` (made absolute). Forge's type emission, which needs every option as tsc sees it, parses `Tsconfig.filePath` with the compiler itself.
60
+
59
61
  Forge debug and Flux consume this map (SWC `jsc.paths` / resolve hooks). Why debug uses it instead of `node_modules` workspace links: [Forge — debug path aliases](../forge/README.md#debug-path-aliases-not-node_modules-links).
60
62
 
61
63
  ## When to use
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Parses JSON with comments and trailing commas, as `tsconfig.json` allows. An empty file is
3
+ * `{}`, as tsc reads it. Throws a `SyntaxError` on anything else that isn't valid JSON.
4
+ */ export function parseJsonc(text) {
5
+ if (text.trim() === "") return {};
6
+ return JSON.parse(stripJsonc(text));
7
+ }
8
+ function stripJsonc(text) {
9
+ let out = "";
10
+ let i = 0;
11
+ while(i < text.length){
12
+ const char = text[i];
13
+ const next = text[i + 1];
14
+ if (char === '"') {
15
+ const end = stringEnd(text, i);
16
+ out += text.slice(i, end);
17
+ i = end;
18
+ } else if (char === "/" && next === "/") {
19
+ const end = text.indexOf("\n", i);
20
+ i = end === -1 ? text.length : end;
21
+ } else if (char === "/" && next === "*") {
22
+ const end = text.indexOf("*/", i + 2);
23
+ if (end === -1) throw new SyntaxError("Unterminated comment in JSON");
24
+ out += " ";
25
+ i = end + 2;
26
+ } else if (char === "}" || char === "]") {
27
+ // Drop a trailing comma before the closing bracket.
28
+ out = out.trimEnd();
29
+ if (out.endsWith(",")) out = out.slice(0, -1);
30
+ out += char;
31
+ i++;
32
+ } else {
33
+ out += char;
34
+ i++;
35
+ }
36
+ }
37
+ return out;
38
+ }
39
+ /** Index just past the string starting at `start` (a `"`); an unclosed string runs to the end. */ function stringEnd(text, start) {
40
+ let i = start + 1;
41
+ while(i < text.length){
42
+ if (text[i] === "\\") i += 2;
43
+ else if (text[i] === '"') return i + 1;
44
+ else i++;
45
+ }
46
+ return text.length;
47
+ }
@@ -13,7 +13,7 @@ import { cache, memoize } from "@decohere/core/caching";
13
13
  import { mixwith } from "@decohere/core/extensibility";
14
14
  import { findFiles, WatchEvents, watch as watchDirectory } from "@decohere/devkit/io";
15
15
  import picomatch from "picomatch";
16
- import { Subject } from "rxjs";
16
+ import { Subject } from "@decohere/core/system";
17
17
  import { WorkspaceConfigurationError } from "../errors.js";
18
18
  import { HasPackageJson } from "./has-package-json.mixin.js";
19
19
  import { HasTsConfig } from "./has-tsconfig.mixin.js";
@@ -1,25 +1,18 @@
1
1
  import fs from "node:fs";
2
2
  import path from "node:path";
3
3
  import { io } from "@decohere/core/io";
4
- import ts from "typescript";
4
+ import { parseTsconfig } from "get-tsconfig";
5
5
  import { WorkspaceConfigurationError } from "../errors.js";
6
- const host = ts.sys;
7
- host.readFile = (file)=>{
8
- return fs.readFileSync(file, {
9
- encoding: "utf8"
10
- });
11
- };
12
- host.readDirectory = (directoryName)=>{
13
- return fs.readdirSync(directoryName, {
14
- withFileTypes: true
15
- }).filter((entry)=>entry.isDirectory()).map((entry)=>entry.name);
16
- };
6
+ import { parseJsonc } from "./jsonc.js";
17
7
  export const DEFAULT_COMPILER_OPTIONS = {
18
8
  emitDeclarationOnly: true,
19
9
  declaration: true,
20
10
  baseUrl: "./"
21
11
  };
22
- export class Tsconfig {
12
+ /**
13
+ * A `tsconfig.json`, read without the TypeScript compiler so running a file doesn't load it.
14
+ * Code that needs the compiler's own parse (type emission) parses `filePath` itself.
15
+ */ export class Tsconfig {
23
16
  static default() {
24
17
  return new Tsconfig();
25
18
  }
@@ -27,34 +20,34 @@ export class Tsconfig {
27
20
  if (!await io.fileExists(filePath)) {
28
21
  throw new WorkspaceConfigurationError(`TSConfig not found ${filePath}`);
29
22
  }
30
- const configFileText = await io.readFile(filePath);
31
- const result = ts.parseConfigFileTextToJson(filePath, configFileText);
32
- if (result.error) {
33
- const errorMessage = result.error.messageText.toString();
34
- throw new WorkspaceConfigurationError(`Error parsing ${filePath}. ${errorMessage}`);
35
- }
36
- const dirName = path.resolve(path.dirname(filePath));
37
- const configParseResult = ts.parseJsonConfigFileContent(result.config, host, dirName);
38
- return new Tsconfig({
39
- compilerOptions: configParseResult.options,
40
- errors: configParseResult.errors
41
- });
23
+ return Tsconfig.read(filePath);
42
24
  }
43
25
  static parseSync(filePath) {
44
26
  if (!Tsconfig.fileExistsSync(filePath)) {
45
27
  throw new WorkspaceConfigurationError(`TSConfig not found ${filePath}`);
46
28
  }
47
- const configFileText = fs.readFileSync(filePath, "utf8");
48
- const result = ts.parseConfigFileTextToJson(filePath, configFileText);
49
- if (result.error) {
50
- const errorMessage = result.error.messageText.toString();
51
- throw new WorkspaceConfigurationError(`Error parsing ${filePath}. ${errorMessage}`);
29
+ return Tsconfig.read(filePath);
30
+ }
31
+ static read(filePath) {
32
+ const fullPath = path.resolve(filePath);
33
+ let compilerOptions;
34
+ try {
35
+ // get-tsconfig reads broken JSON as `{}`; check the file itself first.
36
+ parseJsonc(fs.readFileSync(fullPath, "utf8"));
37
+ compilerOptions = parseTsconfig(fullPath).compilerOptions ?? {};
38
+ } catch (error) {
39
+ const message = error instanceof Error ? error.message : String(error);
40
+ throw new WorkspaceConfigurationError(`Error parsing ${filePath}. ${message}`, {
41
+ cause: error
42
+ });
52
43
  }
53
- const dirName = path.resolve(path.dirname(filePath));
54
- const configParseResult = ts.parseJsonConfigFileContent(result.config, host, dirName);
44
+ const { baseUrl } = compilerOptions;
55
45
  return new Tsconfig({
56
- compilerOptions: configParseResult.options,
57
- errors: configParseResult.errors
46
+ filePath: fullPath,
47
+ compilerOptions: baseUrl == null ? compilerOptions : {
48
+ ...compilerOptions,
49
+ baseUrl: path.resolve(path.dirname(fullPath), baseUrl)
50
+ }
58
51
  });
59
52
  }
60
53
  static fileExistsSync(filePath) {
@@ -69,6 +62,6 @@ export class Tsconfig {
69
62
  }){
70
63
  Object.assign(this, data);
71
64
  }
65
+ /** Absolute path of the file read; undefined for {@link Tsconfig.default}. */ filePath;
72
66
  compilerOptions;
73
- errors;
74
67
  }
@@ -10,7 +10,7 @@ function _ts_metadata(k, v) {
10
10
  import { injectable } from "@decohere/crucible/decorators";
11
11
  import { collections } from "@decohere/core/collections";
12
12
  import { mixwith } from "@decohere/core/extensibility";
13
- import { Subject } from "rxjs";
13
+ import { Subject } from "@decohere/core/system";
14
14
  import { WorkspaceConfigurationError } from "../errors.js";
15
15
  import { HasPackageJson } from "./has-package-json.mixin.js";
16
16
  import { HasTsConfig } from "./has-tsconfig.mixin.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decohere/workspace",
3
- "version": "0.0.1-dev.130",
3
+ "version": "0.0.1-dev.20261105.103",
4
4
  "description": "Workspace and project model primitives for monorepo tooling",
5
5
  "keywords": [
6
6
  "typescript",
@@ -25,20 +25,18 @@
25
25
  "exports": {
26
26
  ".": {
27
27
  "types": "./types/src/index.d.ts",
28
- "import": "./es6/src/index.js",
29
- "require": "./commonjs/src/index.js"
28
+ "import": "./es6/src/index.js"
30
29
  }
31
30
  },
32
31
  "scripts": {
33
32
  "test": "echo \"Error: no test specified\" && exit 1"
34
33
  },
35
34
  "dependencies": {
36
- "@decohere/core": "0.0.1-dev.130",
37
- "@decohere/crucible": "0.0.1-dev.130",
38
- "@decohere/devkit": "0.0.1-dev.130",
39
- "picomatch": "^4.0.4",
40
- "rxjs": "^7.8.2",
41
- "typescript": "^6.0.3"
35
+ "@decohere/core": "0.0.1-dev.20261105.103",
36
+ "@decohere/crucible": "0.0.1-dev.20261105.103",
37
+ "@decohere/devkit": "0.0.1-dev.20261105.103",
38
+ "get-tsconfig": "^4.14.3",
39
+ "picomatch": "^4.0.4"
42
40
  },
43
41
  "devDependencies": {}
44
42
  }
@@ -12,6 +12,7 @@ export type { ProjectConfig, ProjectSeed } from "./models/project.model.js";
12
12
  export { Project } from "./models/project.model.js";
13
13
  export { sourceExtensions } from "./models/source-extensions.js";
14
14
  export type { ProjectFileEvent } from "./models/project-file-event.js";
15
+ export type { CompilerOptions } from "./models/tsconfig.model.js";
15
16
  export { DEFAULT_COMPILER_OPTIONS, Tsconfig } from "./models/tsconfig.model.js";
16
17
  export { Workspace } from "./models/workspace.model.js";
17
18
  export type { Configuration, ProjectOptions, UiConfig, WorkspaceFactoryOptions, WorkspaceOptions, } from "./models/workspace-config.type.js";
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Parses JSON with comments and trailing commas, as `tsconfig.json` allows. An empty file is
3
+ * `{}`, as tsc reads it. Throws a `SyntaxError` on anything else that isn't valid JSON.
4
+ */
5
+ export declare function parseJsonc(text: string): unknown;
@@ -33,7 +33,7 @@ export declare class Project extends Project_base {
33
33
  get dockerConfig(): import("./workspace-config.type.js").DockerConfig;
34
34
  get uiConfig(): import("./workspace-config.type.js").UiConfig;
35
35
  get configurations(): Configuration[];
36
- get projectFileChanged$(): import("rxjs").Observable<ProjectFileEvent>;
36
+ get projectFileChanged$(): import("@decohere/core/system").Observable<ProjectFileEvent>;
37
37
  getAllFiles(): Promise<FileEx[]>;
38
38
  isSourceFile(file: FileEx): boolean;
39
39
  watch(configuration: string): Promise<Watcher>;
@@ -1,11 +1,19 @@
1
- import ts, { type CompilerOptions } from "typescript";
1
+ import { type TsConfigJson } from "get-tsconfig";
2
+ /** `compilerOptions` as written in `tsconfig.json`, after `extends`; `baseUrl` is absolute. */
3
+ export type CompilerOptions = TsConfigJson.CompilerOptions;
2
4
  export declare const DEFAULT_COMPILER_OPTIONS: CompilerOptions;
5
+ /**
6
+ * A `tsconfig.json`, read without the TypeScript compiler so running a file doesn't load it.
7
+ * Code that needs the compiler's own parse (type emission) parses `filePath` itself.
8
+ */
3
9
  export declare class Tsconfig {
4
10
  static default(): Tsconfig;
5
11
  static parse(filePath: string): Promise<Tsconfig>;
6
12
  static parseSync(filePath: string): Tsconfig;
13
+ private static read;
7
14
  private static fileExistsSync;
8
15
  constructor(data?: Partial<Tsconfig>);
16
+ /** Absolute path of the file read; undefined for {@link Tsconfig.default}. */
17
+ readonly filePath?: string;
9
18
  readonly compilerOptions: CompilerOptions;
10
- readonly errors: readonly ts.Diagnostic[];
11
19
  }
@@ -37,7 +37,7 @@ export declare class Workspace extends Workspace_base {
37
37
  watch(configuration: string): Promise<void>;
38
38
  stopWatching(): void;
39
39
  [Symbol.dispose](): void;
40
- get projectFileChanged$(): import("rxjs").Observable<ProjectFileEvent>;
40
+ get projectFileChanged$(): import("@decohere/core/system").Observable<ProjectFileEvent>;
41
41
  findProject(filePath: string, buildConfig: string): Promise<Project | undefined>;
42
42
  private sourcePathsOf;
43
43
  private validateWorkspace;
@@ -1,69 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for(var name in all)Object.defineProperty(target, name, {
7
- enumerable: true,
8
- get: Object.getOwnPropertyDescriptor(all, name).get
9
- });
10
- }
11
- _export(exports, {
12
- get FIXTURES () {
13
- return FIXTURES;
14
- },
15
- get NODE_MODULES () {
16
- return NODE_MODULES;
17
- },
18
- get PACKAGE_JSON () {
19
- return PACKAGE_JSON;
20
- },
21
- get PROJECTS_DIR () {
22
- return PROJECTS_DIR;
23
- },
24
- get TS_CONFIG () {
25
- return TS_CONFIG;
26
- },
27
- get WORKSPACE_CONFIG () {
28
- return WORKSPACE_CONFIG;
29
- },
30
- get WorkspaceDefaults () {
31
- return WorkspaceDefaults;
32
- }
33
- });
34
- const TS_CONFIG = "tsconfig.json";
35
- const PACKAGE_JSON = "package.json";
36
- const NODE_MODULES = "node_modules";
37
- const FIXTURES = "__fixtures__";
38
- const WORKSPACE_CONFIG = ".decohere.js";
39
- const PROJECTS_DIR = "projects";
40
- const WorkspaceDefaults = {
41
- rootDir: "./",
42
- outDir: "dist",
43
- includeProjects: [
44
- `${PROJECTS_DIR}/**/${PACKAGE_JSON}`
45
- ],
46
- ignoreProjects: [
47
- `**/${NODE_MODULES}/**`,
48
- `**/${FIXTURES}/**`,
49
- "**/dist/**"
50
- ],
51
- include: [
52
- "**/*.ts",
53
- "**/*.tsx",
54
- "**/*.mts",
55
- "**/*.cts"
56
- ],
57
- ignore: [
58
- "**/*.d.ts",
59
- "**/*.d.mts",
60
- "**/*.d.cts",
61
- `**/${NODE_MODULES}/**`
62
- ],
63
- copyFiles: [],
64
- configurations: [
65
- {
66
- name: "debug"
67
- }
68
- ]
69
- };
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "WorkspaceConfigurationError", {
6
- enumerable: true,
7
- get: function() {
8
- return WorkspaceConfigurationError;
9
- }
10
- });
11
- class WorkspaceConfigurationError extends Error {
12
- }
@@ -1,90 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "UserConfigFactory", {
6
- enumerable: true,
7
- get: function() {
8
- return UserConfigFactory;
9
- }
10
- });
11
- const _nodepath = /*#__PURE__*/ _interop_require_default(require("node:path"));
12
- const _nodeurl = require("node:url");
13
- const _caching = require("@decohere/core/caching");
14
- const _io = require("@decohere/core/io");
15
- const _const = require("../const.js");
16
- function _interop_require_default(obj) {
17
- return obj && obj.__esModule ? obj : {
18
- default: obj
19
- };
20
- }
21
- function _getRequireWildcardCache(nodeInterop) {
22
- if (typeof WeakMap !== "function") return null;
23
- var cacheBabelInterop = new WeakMap();
24
- var cacheNodeInterop = new WeakMap();
25
- return (_getRequireWildcardCache = function(nodeInterop) {
26
- return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
27
- })(nodeInterop);
28
- }
29
- function _interop_require_wildcard(obj, nodeInterop) {
30
- if (!nodeInterop && obj && obj.__esModule) {
31
- return obj;
32
- }
33
- if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
34
- return {
35
- default: obj
36
- };
37
- }
38
- var cache = _getRequireWildcardCache(nodeInterop);
39
- if (cache && cache.has(obj)) {
40
- return cache.get(obj);
41
- }
42
- var newObj = {
43
- __proto__: null
44
- };
45
- var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
46
- for(var key in obj){
47
- if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
48
- var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
49
- if (desc && (desc.get || desc.set)) {
50
- Object.defineProperty(newObj, key, desc);
51
- } else {
52
- newObj[key] = obj[key];
53
- }
54
- }
55
- }
56
- newObj.default = obj;
57
- if (cache) {
58
- cache.set(obj, newObj);
59
- }
60
- return newObj;
61
- }
62
- function _ts_decorate(decorators, target, key, desc) {
63
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
64
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
65
- else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
66
- return c > 3 && r && Object.defineProperty(target, key, r), r;
67
- }
68
- function _ts_metadata(k, v) {
69
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
70
- }
71
- class ConfigFactory {
72
- async getUserConfig(configFile) {
73
- const file = configFile ?? _const.WORKSPACE_CONFIG;
74
- if (!file || !await _io.io.fileExists(file)) {
75
- return {};
76
- }
77
- const fileUrl = (0, _nodeurl.pathToFileURL)(_nodepath.default.resolve(file)).href;
78
- const conf = (await Promise.resolve(fileUrl).then((p)=>/*#__PURE__*/ _interop_require_wildcard(require(p)))).default;
79
- return conf;
80
- }
81
- }
82
- _ts_decorate([
83
- (0, _caching.cache)(),
84
- _ts_metadata("design:type", Function),
85
- _ts_metadata("design:paramtypes", [
86
- String
87
- ]),
88
- _ts_metadata("design:returntype", Promise)
89
- ], ConfigFactory.prototype, "getUserConfig", null);
90
- const UserConfigFactory = new ConfigFactory();
@@ -1,104 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "ProjectFactory", {
6
- enumerable: true,
7
- get: function() {
8
- return ProjectFactory;
9
- }
10
- });
11
- const _nodepath = /*#__PURE__*/ _interop_require_default(require("node:path"));
12
- const _io = require("@decohere/core/io");
13
- const _io1 = require("@decohere/devkit/io");
14
- const _objects = require("@decohere/core/objects");
15
- const _const = require("../const.js");
16
- const _errors = require("../errors.js");
17
- const _packagejsonmodel = require("../models/package-json.model.js");
18
- const _projectmodel = require("../models/project.model.js");
19
- function _interop_require_default(obj) {
20
- return obj && obj.__esModule ? obj : {
21
- default: obj
22
- };
23
- }
24
- class ProjectFactory {
25
- static async getProjectSeeds(config) {
26
- const { includeProjects, ignoreProjects, rootDir } = config;
27
- const cwd = rootDir ?? "./";
28
- const discoveredPackageJsonFiles = await (0, _io1.findFiles)(includeProjects, {
29
- cwd,
30
- ignore: ignoreProjects
31
- });
32
- const packageJsonFiles = ProjectFactory.filterNestedPackageJsonFiles(discoveredPackageJsonFiles);
33
- if (packageJsonFiles.length === 0 && await ProjectFactory.isStandalone(config)) {
34
- return [
35
- await ProjectFactory.standaloneProject(config)
36
- ];
37
- }
38
- const projects = await Promise.all(packageJsonFiles.map((file)=>ProjectFactory.projectFrom(file, config)));
39
- return projects.sort((a, b)=>a.name.localeCompare(b.name));
40
- }
41
- /**
42
- * A standalone project: no `projects/` folder and no `includeProjects` of the user's own, but
43
- * a root `package.json`. That `package.json` is then the one project, at the root.
44
- */ static async isStandalone(config) {
45
- const rootDir = config.rootDir ?? "./";
46
- const defaultInclude = JSON.stringify(config.includeProjects) === JSON.stringify(_const.WorkspaceDefaults.includeProjects);
47
- return defaultInclude && !await _io.io.directoryExists(_nodepath.default.join(rootDir, _const.PROJECTS_DIR)) && await _io.io.fileExists(_nodepath.default.join(rootDir, _const.PACKAGE_JSON));
48
- }
49
- /** The root `package.json` as the one project. Build output and `.git` aren't its sources. */ static async standaloneProject(config) {
50
- const [packageJsonFile] = await (0, _io1.findFiles)([
51
- _const.PACKAGE_JSON
52
- ], {
53
- cwd: config.rootDir ?? "./"
54
- });
55
- const outDir = (config.outDir ?? _const.WorkspaceDefaults.outDir).replace(/[/\\]+$/, "");
56
- const ignore = [
57
- ...config.ignore ?? [],
58
- `${outDir}/**`,
59
- ".git/**"
60
- ];
61
- return ProjectFactory.projectFrom(packageJsonFile, {
62
- ...config,
63
- ignore
64
- });
65
- }
66
- static filterNestedPackageJsonFiles(files) {
67
- const normalize = (filePath)=>filePath.replaceAll("\\", "/");
68
- const packageJsonSet = new Set(files.map((file)=>normalize(file.relativePath)));
69
- return files.filter((file)=>{
70
- const relativePath = normalize(file.relativePath);
71
- const projectDir = _nodepath.default.posix.dirname(relativePath);
72
- let dir = _nodepath.default.posix.dirname(projectDir);
73
- while(dir !== "." && dir !== "/"){
74
- if (packageJsonSet.has(`${dir}/package.json`)) {
75
- return false;
76
- }
77
- dir = _nodepath.default.posix.dirname(dir);
78
- }
79
- return true;
80
- });
81
- }
82
- static async getProjects(config, configuration) {
83
- const seeds = await ProjectFactory.getProjectSeeds(config);
84
- return seeds.map((seed)=>new _projectmodel.Project(seed.name, seed.config, configuration));
85
- }
86
- static async projectFrom(file, config) {
87
- const packageJsonData = await _io.io.readJsonFile(file.fullPath).catch((error)=>{
88
- throw new _errors.WorkspaceConfigurationError(`Error reading package.json ${file.fullPath}`, error);
89
- });
90
- const name = packageJsonData.name;
91
- const packageJson = new _packagejsonmodel.PackageJson(packageJsonData);
92
- const projectDir = _nodepath.default.dirname(file.relativePath);
93
- const mergedConfig = _objects.merge.withOptions({
94
- mergeArrays: false
95
- }, config, config?.projects?.[name] ?? {}, {
96
- projectDir,
97
- packageJson
98
- });
99
- return {
100
- name,
101
- config: mergedConfig
102
- };
103
- }
104
- }
@@ -1,50 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "WorkspaceFactory", {
6
- enumerable: true,
7
- get: function() {
8
- return WorkspaceFactory;
9
- }
10
- });
11
- const _nodepath = /*#__PURE__*/ _interop_require_default(require("node:path"));
12
- const _io = require("@decohere/core/io");
13
- const _objects = require("@decohere/core/objects");
14
- const _const = require("../const.js");
15
- const _packagejsonmodel = require("../models/package-json.model.js");
16
- const _workspacemodel = require("../models/workspace.model.js");
17
- const _configfactory = require("./config.factory.js");
18
- const _projectfactory = require("./project.factory.js");
19
- function _interop_require_default(obj) {
20
- return obj && obj.__esModule ? obj : {
21
- default: obj
22
- };
23
- }
24
- class Factory {
25
- async create(options = {}) {
26
- const config = await this.getMergedConfig(options);
27
- const projectSeeds = await _projectfactory.ProjectFactory.getProjectSeeds(config);
28
- const packageJson = await this.getPackageJson(config.rootDir ?? "./");
29
- const workspace = new _workspacemodel.Workspace({
30
- packageJson,
31
- config,
32
- projects: projectSeeds
33
- });
34
- return workspace;
35
- }
36
- async getMergedConfig(options) {
37
- const { configFile, ...rest } = options;
38
- const userConfig = await _configfactory.UserConfigFactory.getUserConfig(configFile);
39
- return _objects.merge.withOptions({
40
- mergeArrays: false
41
- }, _const.WorkspaceDefaults, userConfig, rest);
42
- }
43
- async getPackageJson(rootDir) {
44
- const packageJsonPath = _nodepath.default.join(rootDir, _const.PACKAGE_JSON);
45
- if (!await _io.io.fileExists(packageJsonPath)) return;
46
- const data = await _io.io.readJsonFile(packageJsonPath);
47
- return new _packagejsonmodel.PackageJson(data);
48
- }
49
- }
50
- const WorkspaceFactory = new Factory();
@@ -1,70 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for(var name in all)Object.defineProperty(target, name, {
7
- enumerable: true,
8
- get: Object.getOwnPropertyDescriptor(all, name).get
9
- });
10
- }
11
- _export(exports, {
12
- get DEFAULT_COMPILER_OPTIONS () {
13
- return _tsconfigmodel.DEFAULT_COMPILER_OPTIONS;
14
- },
15
- get HasPackageJson () {
16
- return _haspackagejsonmixin.HasPackageJson;
17
- },
18
- get HasTsConfig () {
19
- return _hastsconfigmixin.HasTsConfig;
20
- },
21
- get PackageJson () {
22
- return _packagejsonmodel.PackageJson;
23
- },
24
- get Project () {
25
- return _projectmodel.Project;
26
- },
27
- get ProjectFactory () {
28
- return _projectfactory.ProjectFactory;
29
- },
30
- get Tsconfig () {
31
- return _tsconfigmodel.Tsconfig;
32
- },
33
- get UserConfigFactory () {
34
- return _configfactory.UserConfigFactory;
35
- },
36
- get WORKSPACE_CONFIG () {
37
- return _const.WORKSPACE_CONFIG;
38
- },
39
- get Workspace () {
40
- return _workspacemodel.Workspace;
41
- },
42
- get WorkspaceConfigurationError () {
43
- return _errors.WorkspaceConfigurationError;
44
- },
45
- get WorkspaceDefaults () {
46
- return _const.WorkspaceDefaults;
47
- },
48
- get WorkspaceFactory () {
49
- return _workspacefactory.WorkspaceFactory;
50
- },
51
- get packageAliases () {
52
- return _packagealiases.packageAliases;
53
- },
54
- get sourceExtensions () {
55
- return _sourceextensions.sourceExtensions;
56
- }
57
- });
58
- const _const = require("./const.js");
59
- const _errors = require("./errors.js");
60
- const _configfactory = require("./factories/config.factory.js");
61
- const _projectfactory = require("./factories/project.factory.js");
62
- const _workspacefactory = require("./factories/workspace.factory.js");
63
- const _haspackagejsonmixin = require("./models/has-package-json.mixin.js");
64
- const _hastsconfigmixin = require("./models/has-tsconfig.mixin.js");
65
- const _packagealiases = require("./models/package-aliases.js");
66
- const _packagejsonmodel = require("./models/package-json.model.js");
67
- const _projectmodel = require("./models/project.model.js");
68
- const _sourceextensions = require("./models/source-extensions.js");
69
- const _tsconfigmodel = require("./models/tsconfig.model.js");
70
- const _workspacemodel = require("./models/workspace.model.js");