@decohere/workspace 0.0.1-dev.125 → 0.0.1-dev.5
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/package.json +3 -13
- package/src/const.ts +19 -0
- package/src/errors.ts +1 -0
- package/src/factories/config.factory.ts +21 -0
- package/src/factories/find-workspace-root.ts +32 -0
- package/src/factories/project.factory.ts +75 -0
- package/src/factories/workspace.factory.ts +44 -0
- package/{types/src/index.d.ts → src/index.ts} +7 -1
- package/src/models/has-package-json.mixin.ts +30 -0
- package/src/models/has-tsconfig.mixin.ts +48 -0
- package/src/models/package-aliases.ts +130 -0
- package/src/models/package-json.model.ts +231 -0
- package/src/models/project-file-event.ts +9 -0
- package/src/models/project.model.ts +340 -0
- package/src/models/source-extensions.ts +59 -0
- package/src/models/tsconfig.model.ts +81 -0
- package/src/models/workspace-config.type.ts +57 -0
- package/src/models/workspace.model.ts +178 -0
- package/tests/find-workspace-root.spec.ts +30 -0
- package/tests/package-aliases.spec.ts +160 -0
- package/tests/package-json.model.spec.ts +78 -0
- package/tests/project.factory.spec.ts +100 -0
- package/tests/source-extensions.spec.ts +33 -0
- package/tests/workspace.factory.spec.ts +147 -0
- package/LICENSE +0 -15
- package/commonjs/src/const.js +0 -69
- package/commonjs/src/errors.js +0 -12
- package/commonjs/src/factories/config.factory.js +0 -90
- package/commonjs/src/factories/find-workspace-root.js +0 -37
- package/commonjs/src/factories/project.factory.js +0 -73
- package/commonjs/src/factories/workspace.factory.js +0 -50
- package/commonjs/src/index.js +0 -74
- package/commonjs/src/models/has-package-json.mixin.js +0 -50
- package/commonjs/src/models/has-tsconfig.mixin.js +0 -75
- package/commonjs/src/models/package-aliases.js +0 -112
- package/commonjs/src/models/package-json.model.js +0 -202
- package/commonjs/src/models/project-file-event.js +0 -4
- package/commonjs/src/models/project.model.js +0 -316
- package/commonjs/src/models/source-extensions.js +0 -81
- package/commonjs/src/models/tsconfig.model.js +0 -97
- package/commonjs/src/models/workspace-config.type.js +0 -7
- package/commonjs/src/models/workspace.model.js +0 -153
- package/es6/src/const.js +0 -36
- package/es6/src/errors.js +0 -2
- package/es6/src/factories/config.factory.js +0 -34
- package/es6/src/factories/find-workspace-root.js +0 -26
- package/es6/src/factories/project.factory.js +0 -58
- package/es6/src/factories/workspace.factory.js +0 -35
- package/es6/src/index.js +0 -14
- package/es6/src/models/has-package-json.mixin.js +0 -35
- package/es6/src/models/has-tsconfig.mixin.js +0 -60
- package/es6/src/models/package-aliases.js +0 -97
- package/es6/src/models/package-json.model.js +0 -192
- package/es6/src/models/project-file-event.js +0 -1
- package/es6/src/models/project.model.js +0 -301
- package/es6/src/models/source-extensions.js +0 -66
- package/es6/src/models/tsconfig.model.js +0 -74
- package/es6/src/models/workspace-config.type.js +0 -4
- package/es6/src/models/workspace.model.js +0 -143
- package/types/src/const.d.ts +0 -8
- package/types/src/errors.d.ts +0 -2
- package/types/src/factories/config.factory.d.ts +0 -6
- package/types/src/factories/find-workspace-root.d.ts +0 -6
- package/types/src/factories/project.factory.d.ts +0 -8
- package/types/src/factories/workspace.factory.d.ts +0 -9
- package/types/src/models/has-package-json.mixin.d.ts +0 -9
- package/types/src/models/has-tsconfig.mixin.d.ts +0 -11
- package/types/src/models/package-aliases.d.ts +0 -28
- package/types/src/models/package-json.model.d.ts +0 -40
- package/types/src/models/project-file-event.d.ts +0 -9
- package/types/src/models/project.model.d.ts +0 -64
- package/types/src/models/source-extensions.d.ts +0 -22
- package/types/src/models/tsconfig.model.d.ts +0 -11
- package/types/src/models/workspace-config.type.d.ts +0 -52
- package/types/src/models/workspace.model.d.ts +0 -40
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { WorkspaceFactory, type WorkspaceOptions } from "@decohere/workspace";
|
|
2
|
+
import { resetMemfs } from "@decohere/core/testing";
|
|
3
|
+
import { fs, vol } from "memfs";
|
|
4
|
+
import { afterEach, beforeEach, expect, it, vi } from "vitest";
|
|
5
|
+
|
|
6
|
+
const root = "/MOCK_ROOT";
|
|
7
|
+
const projects = "projects";
|
|
8
|
+
const projPath = `${projects}/path/to`;
|
|
9
|
+
const projPath2 = `${projects}/path/other`;
|
|
10
|
+
const MOCK_PROJ1 = "MOCK_PROJ1";
|
|
11
|
+
const MOCK_PROJ2 = "MOCK_PROJ2";
|
|
12
|
+
|
|
13
|
+
const defaultOptions: WorkspaceOptions = {
|
|
14
|
+
rootDir: root,
|
|
15
|
+
outDir: "dist",
|
|
16
|
+
includeProjects: ["projects/**/package.json"],
|
|
17
|
+
ignoreProjects: ["**/node_modules/**", "**/__fixtures__/**"],
|
|
18
|
+
copyFiles: [],
|
|
19
|
+
configurations: [{ name: "debug" }],
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const mockFiles = {
|
|
23
|
+
[`${root}/package.json`]: JSON.stringify({ name: "ROOT" }),
|
|
24
|
+
[`${root}/${projPath}/package.json`]: JSON.stringify({ name: MOCK_PROJ1 }),
|
|
25
|
+
[`${root}/${projPath}/src/index.ts`]: "export const value = 1;",
|
|
26
|
+
[`${root}/${projPath2}/package.json`]: JSON.stringify({ name: MOCK_PROJ2 }),
|
|
27
|
+
} satisfies Record<string, string>;
|
|
28
|
+
|
|
29
|
+
beforeEach(() => {
|
|
30
|
+
vi.spyOn(process, "cwd").mockReturnValue(root);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
afterEach(() => {
|
|
34
|
+
resetMemfs();
|
|
35
|
+
vi.restoreAllMocks();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("creates a workspace and discovers projects", async () => {
|
|
39
|
+
vol.fromJSON(mockFiles);
|
|
40
|
+
const workspace = await WorkspaceFactory.create(defaultOptions);
|
|
41
|
+
expect(workspace.getProjects("debug")).toHaveLength(2);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("ignores node_modules", async () => {
|
|
45
|
+
vol.fromJSON({
|
|
46
|
+
...mockFiles,
|
|
47
|
+
[`${root}/${projPath}/node_modules/foo/package.json`]: JSON.stringify({ name: "LIB" }),
|
|
48
|
+
});
|
|
49
|
+
const workspace = await WorkspaceFactory.create(defaultOptions);
|
|
50
|
+
expect(workspace.getProjects("debug")).toHaveLength(2);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("ignores fixture folders", async () => {
|
|
54
|
+
vol.fromJSON({
|
|
55
|
+
...mockFiles,
|
|
56
|
+
[`${root}/${projPath}/__fixtures__/foo/package.json`]: JSON.stringify({ name: "LIB" }),
|
|
57
|
+
});
|
|
58
|
+
const workspace = await WorkspaceFactory.create(defaultOptions);
|
|
59
|
+
expect(workspace.getProjects("debug")).toHaveLength(2);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("creates workspace projects with expected directories", async () => {
|
|
63
|
+
vol.fromJSON(mockFiles);
|
|
64
|
+
const workspace = await WorkspaceFactory.create(defaultOptions);
|
|
65
|
+
const projectNamesToDirs = workspace
|
|
66
|
+
.getProjects("debug")
|
|
67
|
+
.map((p) => [p.name, p.projectDirectory] as const);
|
|
68
|
+
|
|
69
|
+
expect(projectNamesToDirs).toEqual(
|
|
70
|
+
expect.arrayContaining([
|
|
71
|
+
[MOCK_PROJ1, projPath],
|
|
72
|
+
[MOCK_PROJ2, projPath2],
|
|
73
|
+
]),
|
|
74
|
+
);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("throws when duplicate project names exist", async () => {
|
|
78
|
+
vol.fromJSON({
|
|
79
|
+
...mockFiles,
|
|
80
|
+
[`${root}/${projects}/duplicate/package.json`]: JSON.stringify({ name: MOCK_PROJ1 }),
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
await expect(() => WorkspaceFactory.create(defaultOptions)).rejects.toThrow();
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("creates a project with default include when no options are passed (flux path)", async () => {
|
|
87
|
+
const root = "/FLUX_ROOT";
|
|
88
|
+
vol.fromJSON({
|
|
89
|
+
[`${root}/projects/app/package.json`]: JSON.stringify({
|
|
90
|
+
name: "my-app",
|
|
91
|
+
main: "src/index.ts",
|
|
92
|
+
}),
|
|
93
|
+
[`${root}/projects/app/src/index.ts`]: "export default {};",
|
|
94
|
+
});
|
|
95
|
+
vi.spyOn(process, "cwd").mockReturnValue(root);
|
|
96
|
+
|
|
97
|
+
// FluxModule.createWorkspace calls WorkspaceFactory.create({ configFile: undefined })
|
|
98
|
+
// — the workspace package's WorkspaceDefaults provides the TypeScript includes, so fileInfoMap is populated.
|
|
99
|
+
const workspace = await WorkspaceFactory.create({ configFile: undefined, rootDir: root });
|
|
100
|
+
const projects = workspace.getProjects("debug");
|
|
101
|
+
|
|
102
|
+
expect(projects).toHaveLength(1);
|
|
103
|
+
expect(projects[0].include).toEqual(["**/*.ts", "**/*.tsx", "**/*.mts", "**/*.cts"]);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("fires projectFileChanged$ when a source file is written after watch starts", async () => {
|
|
107
|
+
const root = "/WATCH_ROOT";
|
|
108
|
+
const filePath = `${root}/projects/app/src/index.ts`;
|
|
109
|
+
vol.fromJSON({
|
|
110
|
+
[`${root}/projects/app/package.json`]: JSON.stringify({
|
|
111
|
+
name: "watch-app",
|
|
112
|
+
main: "src/index.ts",
|
|
113
|
+
}),
|
|
114
|
+
[filePath]: "export const v = 1;",
|
|
115
|
+
});
|
|
116
|
+
vi.spyOn(process, "cwd").mockReturnValue(root);
|
|
117
|
+
|
|
118
|
+
const workspace = await WorkspaceFactory.create({ configFile: undefined, rootDir: root });
|
|
119
|
+
|
|
120
|
+
// workspace.watch() calls project.watch() internally and subscribes project events
|
|
121
|
+
// into workspace.projectFileChanged$
|
|
122
|
+
await workspace.watch("debug");
|
|
123
|
+
|
|
124
|
+
const [project] = workspace.getProjects("debug");
|
|
125
|
+
|
|
126
|
+
await new Promise<void>((resolve, reject) => {
|
|
127
|
+
const subscription = workspace.projectFileChanged$.subscribe((evt) => {
|
|
128
|
+
if (evt.file.relativePath !== "src/index.ts") return;
|
|
129
|
+
subscription.unsubscribe();
|
|
130
|
+
workspace.stopWatching();
|
|
131
|
+
resolve();
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
// project.watch() was already called by workspace.watch(); use its ready promise
|
|
135
|
+
project.watch("debug").then((watcher) => {
|
|
136
|
+
watcher.ready.then(() => {
|
|
137
|
+
fs.writeFileSync(filePath, "export const v = 2;", { encoding: "utf8" });
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
setTimeout(() => {
|
|
142
|
+
subscription.unsubscribe();
|
|
143
|
+
workspace.stopWatching();
|
|
144
|
+
reject(new Error("projectFileChanged$ did not fire within timeout"));
|
|
145
|
+
}, 800);
|
|
146
|
+
});
|
|
147
|
+
});
|
package/LICENSE
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
ISC License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025-2026 Typesmiths
|
|
4
|
-
|
|
5
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
-
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
-
copyright notice and this permission notice appear in all copies.
|
|
8
|
-
|
|
9
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
10
|
-
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
11
|
-
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
12
|
-
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
13
|
-
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
14
|
-
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
15
|
-
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
package/commonjs/src/const.js
DELETED
|
@@ -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
|
-
};
|
package/commonjs/src/errors.js
DELETED
|
@@ -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,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "findWorkspaceRoot", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return findWorkspaceRoot;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _nodefs = require("node:fs");
|
|
12
|
-
const _nodepath = /*#__PURE__*/ _interop_require_default(require("node:path"));
|
|
13
|
-
const _const = require("../const.js");
|
|
14
|
-
function _interop_require_default(obj) {
|
|
15
|
-
return obj && obj.__esModule ? obj : {
|
|
16
|
-
default: obj
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
function findWorkspaceRoot(startDir) {
|
|
20
|
-
const start = _nodepath.default.resolve(startDir);
|
|
21
|
-
let dir = start;
|
|
22
|
-
for(;;){
|
|
23
|
-
if ((0, _nodefs.existsSync)(_nodepath.default.join(dir, _const.PACKAGE_JSON)) && isDirectory(_nodepath.default.join(dir, _const.PROJECTS_DIR))) {
|
|
24
|
-
return dir;
|
|
25
|
-
}
|
|
26
|
-
const parent = _nodepath.default.dirname(dir);
|
|
27
|
-
if (parent === dir) return start;
|
|
28
|
-
dir = parent;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
function isDirectory(fullPath) {
|
|
32
|
-
try {
|
|
33
|
-
return (0, _nodefs.statSync)(fullPath).isDirectory();
|
|
34
|
-
} catch {
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
@@ -1,73 +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 _errors = require("../errors.js");
|
|
16
|
-
const _packagejsonmodel = require("../models/package-json.model.js");
|
|
17
|
-
const _projectmodel = require("../models/project.model.js");
|
|
18
|
-
function _interop_require_default(obj) {
|
|
19
|
-
return obj && obj.__esModule ? obj : {
|
|
20
|
-
default: obj
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
class ProjectFactory {
|
|
24
|
-
static async getProjectSeeds(config) {
|
|
25
|
-
const { includeProjects, ignoreProjects, rootDir } = config;
|
|
26
|
-
const cwd = rootDir ?? "./";
|
|
27
|
-
const discoveredPackageJsonFiles = await (0, _io1.findFiles)(includeProjects, {
|
|
28
|
-
cwd,
|
|
29
|
-
ignore: ignoreProjects
|
|
30
|
-
});
|
|
31
|
-
const packageJsonFiles = ProjectFactory.filterNestedPackageJsonFiles(discoveredPackageJsonFiles);
|
|
32
|
-
const projects = await Promise.all(packageJsonFiles.map((file)=>ProjectFactory.projectFrom(file, config)));
|
|
33
|
-
return projects.sort((a, b)=>a.name.localeCompare(b.name));
|
|
34
|
-
}
|
|
35
|
-
static filterNestedPackageJsonFiles(files) {
|
|
36
|
-
const normalize = (filePath)=>filePath.replaceAll("\\", "/");
|
|
37
|
-
const packageJsonSet = new Set(files.map((file)=>normalize(file.relativePath)));
|
|
38
|
-
return files.filter((file)=>{
|
|
39
|
-
const relativePath = normalize(file.relativePath);
|
|
40
|
-
const projectDir = _nodepath.default.posix.dirname(relativePath);
|
|
41
|
-
let dir = _nodepath.default.posix.dirname(projectDir);
|
|
42
|
-
while(dir !== "." && dir !== "/"){
|
|
43
|
-
if (packageJsonSet.has(`${dir}/package.json`)) {
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
dir = _nodepath.default.posix.dirname(dir);
|
|
47
|
-
}
|
|
48
|
-
return true;
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
static async getProjects(config, configuration) {
|
|
52
|
-
const seeds = await ProjectFactory.getProjectSeeds(config);
|
|
53
|
-
return seeds.map((seed)=>new _projectmodel.Project(seed.name, seed.config, configuration));
|
|
54
|
-
}
|
|
55
|
-
static async projectFrom(file, config) {
|
|
56
|
-
const packageJsonData = await _io.io.readJsonFile(file.fullPath).catch((error)=>{
|
|
57
|
-
throw new _errors.WorkspaceConfigurationError(`Error reading package.json ${file.fullPath}`, error);
|
|
58
|
-
});
|
|
59
|
-
const name = packageJsonData.name;
|
|
60
|
-
const packageJson = new _packagejsonmodel.PackageJson(packageJsonData);
|
|
61
|
-
const projectDir = _nodepath.default.dirname(file.relativePath);
|
|
62
|
-
const mergedConfig = _objects.merge.withOptions({
|
|
63
|
-
mergeArrays: false
|
|
64
|
-
}, config, config?.projects?.[name] ?? {}, {
|
|
65
|
-
projectDir,
|
|
66
|
-
packageJson
|
|
67
|
-
});
|
|
68
|
-
return {
|
|
69
|
-
name,
|
|
70
|
-
config: mergedConfig
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
}
|
|
@@ -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();
|
package/commonjs/src/index.js
DELETED
|
@@ -1,74 +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 findWorkspaceRoot () {
|
|
52
|
-
return _findworkspaceroot.findWorkspaceRoot;
|
|
53
|
-
},
|
|
54
|
-
get packageAliases () {
|
|
55
|
-
return _packagealiases.packageAliases;
|
|
56
|
-
},
|
|
57
|
-
get sourceExtensions () {
|
|
58
|
-
return _sourceextensions.sourceExtensions;
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
const _const = require("./const.js");
|
|
62
|
-
const _errors = require("./errors.js");
|
|
63
|
-
const _configfactory = require("./factories/config.factory.js");
|
|
64
|
-
const _findworkspaceroot = require("./factories/find-workspace-root.js");
|
|
65
|
-
const _projectfactory = require("./factories/project.factory.js");
|
|
66
|
-
const _workspacefactory = require("./factories/workspace.factory.js");
|
|
67
|
-
const _haspackagejsonmixin = require("./models/has-package-json.mixin.js");
|
|
68
|
-
const _hastsconfigmixin = require("./models/has-tsconfig.mixin.js");
|
|
69
|
-
const _packagealiases = require("./models/package-aliases.js");
|
|
70
|
-
const _packagejsonmodel = require("./models/package-json.model.js");
|
|
71
|
-
const _projectmodel = require("./models/project.model.js");
|
|
72
|
-
const _sourceextensions = require("./models/source-extensions.js");
|
|
73
|
-
const _tsconfigmodel = require("./models/tsconfig.model.js");
|
|
74
|
-
const _workspacemodel = require("./models/workspace.model.js");
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "HasPackageJson", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return HasPackageJson;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _nodepath = /*#__PURE__*/ _interop_require_default(require("node:path"));
|
|
12
|
-
const _caching = require("@decohere/core/caching");
|
|
13
|
-
const _io = require("@decohere/core/io");
|
|
14
|
-
const _const = require("../const.js");
|
|
15
|
-
const _packagejsonmodel = require("./package-json.model.js");
|
|
16
|
-
function _interop_require_default(obj) {
|
|
17
|
-
return obj && obj.__esModule ? obj : {
|
|
18
|
-
default: obj
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
22
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
23
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
24
|
-
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;
|
|
25
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
26
|
-
}
|
|
27
|
-
function _ts_metadata(k, v) {
|
|
28
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
29
|
-
}
|
|
30
|
-
class HasPackageJson {
|
|
31
|
-
async getPackageJson() {
|
|
32
|
-
return new _packagejsonmodel.PackageJson(await _io.io.readJsonFile(_nodepath.default.join(this.packageJsonDirectory, _const.PACKAGE_JSON)));
|
|
33
|
-
}
|
|
34
|
-
get packageJsonPath() {
|
|
35
|
-
return _nodepath.default.join(this.packageJsonDirectory, _const.PACKAGE_JSON);
|
|
36
|
-
}
|
|
37
|
-
async getVersion() {
|
|
38
|
-
return (await this.getPackageJson()).version;
|
|
39
|
-
}
|
|
40
|
-
async persistPackageJson(packageJson) {
|
|
41
|
-
await _io.io.writeFile(this.packageJsonPath, packageJson.toJSON());
|
|
42
|
-
_caching.invalidateMemoize.evict(this, HasPackageJson.prototype.getPackageJson);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
_ts_decorate([
|
|
46
|
-
(0, _caching.memoize)(),
|
|
47
|
-
_ts_metadata("design:type", Function),
|
|
48
|
-
_ts_metadata("design:paramtypes", []),
|
|
49
|
-
_ts_metadata("design:returntype", Promise)
|
|
50
|
-
], HasPackageJson.prototype, "getPackageJson", null);
|