@decohere/workspace 0.0.1-dev.116

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.
Files changed (53) hide show
  1. package/README.md +81 -0
  2. package/commonjs/src/const.js +69 -0
  3. package/commonjs/src/errors.js +12 -0
  4. package/commonjs/src/factories/config.factory.js +90 -0
  5. package/commonjs/src/factories/find-workspace-root.js +37 -0
  6. package/commonjs/src/factories/project.factory.js +72 -0
  7. package/commonjs/src/factories/workspace.factory.js +50 -0
  8. package/commonjs/src/index.js +74 -0
  9. package/commonjs/src/models/has-package-json.mixin.js +50 -0
  10. package/commonjs/src/models/has-tsconfig.mixin.js +75 -0
  11. package/commonjs/src/models/package-aliases.js +112 -0
  12. package/commonjs/src/models/package-json.model.js +196 -0
  13. package/commonjs/src/models/project-file-event.js +4 -0
  14. package/commonjs/src/models/project.model.js +316 -0
  15. package/commonjs/src/models/source-extensions.js +81 -0
  16. package/commonjs/src/models/tsconfig.model.js +97 -0
  17. package/commonjs/src/models/workspace-config.type.js +7 -0
  18. package/commonjs/src/models/workspace.model.js +153 -0
  19. package/es6/src/const.js +36 -0
  20. package/es6/src/errors.js +2 -0
  21. package/es6/src/factories/config.factory.js +34 -0
  22. package/es6/src/factories/find-workspace-root.js +26 -0
  23. package/es6/src/factories/project.factory.js +57 -0
  24. package/es6/src/factories/workspace.factory.js +35 -0
  25. package/es6/src/index.js +14 -0
  26. package/es6/src/models/has-package-json.mixin.js +35 -0
  27. package/es6/src/models/has-tsconfig.mixin.js +60 -0
  28. package/es6/src/models/package-aliases.js +97 -0
  29. package/es6/src/models/package-json.model.js +186 -0
  30. package/es6/src/models/project-file-event.js +1 -0
  31. package/es6/src/models/project.model.js +301 -0
  32. package/es6/src/models/source-extensions.js +66 -0
  33. package/es6/src/models/tsconfig.model.js +74 -0
  34. package/es6/src/models/workspace-config.type.js +4 -0
  35. package/es6/src/models/workspace.model.js +143 -0
  36. package/package.json +34 -0
  37. package/types/src/const.d.ts +8 -0
  38. package/types/src/errors.d.ts +2 -0
  39. package/types/src/factories/config.factory.d.ts +6 -0
  40. package/types/src/factories/find-workspace-root.d.ts +6 -0
  41. package/types/src/factories/project.factory.d.ts +8 -0
  42. package/types/src/factories/workspace.factory.d.ts +9 -0
  43. package/types/src/index.d.ts +18 -0
  44. package/types/src/models/has-package-json.mixin.d.ts +9 -0
  45. package/types/src/models/has-tsconfig.mixin.d.ts +11 -0
  46. package/types/src/models/package-aliases.d.ts +28 -0
  47. package/types/src/models/package-json.model.d.ts +39 -0
  48. package/types/src/models/project-file-event.d.ts +8 -0
  49. package/types/src/models/project.model.d.ts +64 -0
  50. package/types/src/models/source-extensions.d.ts +22 -0
  51. package/types/src/models/tsconfig.model.d.ts +11 -0
  52. package/types/src/models/workspace-config.type.d.ts +52 -0
  53. package/types/src/models/workspace.model.d.ts +40 -0
package/README.md ADDED
@@ -0,0 +1,81 @@
1
+ # @decohere/workspace
2
+
3
+ Workspace and project model for Decohere tooling. Forge and Flux call it to find packages and derive import aliases. It is not a CLI — you do not run it; tools use it internally.
4
+
5
+ ## Workspace layout
6
+
7
+ A **project** is a directory whose root contains a `package.json`. The workspace package discovers those files with `includeProjects` globs (cwd = the workspace root, usually `process.cwd()`).
8
+
9
+ The workspace root may also have a `package.json`. That file is workspace metadata (name/version). It is **not** a project unless it also matches `includeProjects`.
10
+
11
+ ### Defaults
12
+
13
+ | Option | Default |
14
+ |---|---|
15
+ | `includeProjects` | `projects/**/package.json` |
16
+ | `ignoreProjects` | `**/node_modules/**`, `**/__fixtures__/**`, `**/dist/**` |
17
+ | Source files | `**/*.ts` (not `**/*.d.ts`) |
18
+ | Config file | `.decohere.js` if present; otherwise defaults |
19
+
20
+ Nested `package.json` files under another discovered package are skipped (fixtures inside a project do not become projects).
21
+
22
+ Default tree:
23
+
24
+ ```
25
+ package.json # workspace (not a project)
26
+ projects/api/package.json # project
27
+ projects/lib/package.json # project
28
+ ```
29
+
30
+ Packages do **not** have to live under `projects/` — that is only the default glob. Override `includeProjects` when the tree is different.
31
+
32
+ ### Optional `.decohere.js`
33
+
34
+ If the file is missing, the workspace package uses the defaults above. Arrays in this file **replace** defaults (they are not concatenated).
35
+
36
+ ```js
37
+ /** @type {import("@decohere/workspace").WorkspaceOptions} */
38
+ export default {
39
+ includeProjects: ["apps/**/package.json", "packages/**/package.json"],
40
+ };
41
+ ```
42
+
43
+ Per-project settings go under `projects`, keyed by package name: `docker` (image, Dockerfile, tags, build args) and `ui` (the UI project a deployable ships, see [forge](../forge/README.md#shipping-the-ui-with-the-api)).
44
+
45
+ `--config-file` on `forge` / `flux` selects a different config path. The default filename is still `.decohere.js`.
46
+
47
+ ### Package aliases
48
+
49
+ For each discovered project, the workspace package maps `package.json` `name` to its source entry, and its subpaths to their sources (#518):
50
+
51
+ - **The entry:** a TypeScript `main` as written (default `src/index.ts`). A `main` or `exports["."]` that describes the published layout (`index.js`, `./es6/src/index.js`) maps back to the source under `src/`.
52
+ - **Each subpath in `exports`:** `./auth` → `./es6/src/auth/auth.extensions.js` becomes `src/auth/auth.extensions.ts`. Entries whose source doesn't exist are left out.
53
+ - **Any other subpath (`name/*`):** `src/<sub>.ts` (or `.tsx`, `.mts` for `.mjs`, `.cts` for `.cjs`), else `src/<sub>/index.ts`. A package with only subpaths and no root entry resolves them under `src/`.
54
+
55
+ 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`.
56
+
57
+ 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).
58
+
59
+ ## When to use
60
+
61
+ | Use `@decohere/workspace` | Do not use it |
62
+ |---|---|
63
+ | Discover packages and watch their source | A user-facing “run this workspace” CLI (use Flux / Forge) |
64
+ | Package-name aliases (`Workspace.getPackageAliases`) | pnpm/npm workspace protocol as the discovery source |
65
+ | Shared project model for Forge + Flux | Browser bundler config (Vite / webpack) |
66
+
67
+ ## Programmatic API
68
+
69
+ ```ts
70
+ import { WorkspaceFactory } from "@decohere/workspace";
71
+
72
+ const workspace = await WorkspaceFactory.create({
73
+ configFile: undefined, // workspace defaults; or path to .decohere.js
74
+ rootDir: process.cwd(),
75
+ });
76
+
77
+ const projects = workspace.getProjects("debug");
78
+ const aliases = workspace.getPackageAliases("debug");
79
+ ```
80
+
81
+ Pass a pre-built `workspace` into Forge/Flux in tests to skip filesystem discovery.
@@ -0,0 +1,69 @@
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
+ };
@@ -0,0 +1,12 @@
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
+ }
@@ -0,0 +1,90 @@
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();
@@ -0,0 +1,37 @@
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
+ }
@@ -0,0 +1,72 @@
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 _objects = require("@decohere/core/objects");
14
+ const _errors = require("../errors.js");
15
+ const _packagejsonmodel = require("../models/package-json.model.js");
16
+ const _projectmodel = require("../models/project.model.js");
17
+ function _interop_require_default(obj) {
18
+ return obj && obj.__esModule ? obj : {
19
+ default: obj
20
+ };
21
+ }
22
+ class ProjectFactory {
23
+ static async getProjectSeeds(config) {
24
+ const { includeProjects, ignoreProjects, rootDir } = config;
25
+ const cwd = rootDir ?? "./";
26
+ const discoveredPackageJsonFiles = await _io.io.findFiles(includeProjects, {
27
+ cwd,
28
+ ignore: ignoreProjects
29
+ });
30
+ const packageJsonFiles = ProjectFactory.filterNestedPackageJsonFiles(discoveredPackageJsonFiles);
31
+ const projects = await Promise.all(packageJsonFiles.map((file)=>ProjectFactory.projectFrom(file, config)));
32
+ return projects.sort((a, b)=>a.name.localeCompare(b.name));
33
+ }
34
+ static filterNestedPackageJsonFiles(files) {
35
+ const normalize = (filePath)=>filePath.replaceAll("\\", "/");
36
+ const packageJsonSet = new Set(files.map((file)=>normalize(file.relativePath)));
37
+ return files.filter((file)=>{
38
+ const relativePath = normalize(file.relativePath);
39
+ const projectDir = _nodepath.default.posix.dirname(relativePath);
40
+ let dir = _nodepath.default.posix.dirname(projectDir);
41
+ while(dir !== "." && dir !== "/"){
42
+ if (packageJsonSet.has(`${dir}/package.json`)) {
43
+ return false;
44
+ }
45
+ dir = _nodepath.default.posix.dirname(dir);
46
+ }
47
+ return true;
48
+ });
49
+ }
50
+ static async getProjects(config, configuration) {
51
+ const seeds = await ProjectFactory.getProjectSeeds(config);
52
+ return seeds.map((seed)=>new _projectmodel.Project(seed.name, seed.config, configuration));
53
+ }
54
+ static async projectFrom(file, config) {
55
+ const packageJsonData = await _io.io.readJsonFile(file.fullPath).catch((error)=>{
56
+ throw new _errors.WorkspaceConfigurationError(`Error reading package.json ${file.fullPath}`, error);
57
+ });
58
+ const name = packageJsonData.name;
59
+ const packageJson = new _packagejsonmodel.PackageJson(packageJsonData);
60
+ const projectDir = _nodepath.default.dirname(file.relativePath);
61
+ const mergedConfig = _objects.merge.withOptions({
62
+ mergeArrays: false
63
+ }, config, config?.projects?.[name] ?? {}, {
64
+ projectDir,
65
+ packageJson
66
+ });
67
+ return {
68
+ name,
69
+ config: mergedConfig
70
+ };
71
+ }
72
+ }
@@ -0,0 +1,50 @@
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();
@@ -0,0 +1,74 @@
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");
@@ -0,0 +1,50 @@
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);
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "HasTsConfig", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return HasTsConfig;
9
+ }
10
+ });
11
+ const _nodefs = /*#__PURE__*/ _interop_require_default(require("node:fs"));
12
+ const _nodepath = /*#__PURE__*/ _interop_require_default(require("node:path"));
13
+ const _caching = require("@decohere/core/caching");
14
+ const _io = require("@decohere/core/io");
15
+ const _const = require("../const.js");
16
+ const _tsconfigmodel = require("./tsconfig.model.js");
17
+ function _interop_require_default(obj) {
18
+ return obj && obj.__esModule ? obj : {
19
+ default: obj
20
+ };
21
+ }
22
+ function _ts_decorate(decorators, target, key, desc) {
23
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
24
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
25
+ 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;
26
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
27
+ }
28
+ function _ts_metadata(k, v) {
29
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
30
+ }
31
+ class HasTsConfig {
32
+ async getTsConfig() {
33
+ for (const configPath of this.tsConfigPaths){
34
+ if (await _io.io.fileExists(configPath)) return _tsconfigmodel.Tsconfig.parse(configPath);
35
+ }
36
+ return _tsconfigmodel.Tsconfig.default();
37
+ }
38
+ getTsConfigSync() {
39
+ const configPath = this.findTsConfigPath();
40
+ if (configPath != null) return _tsconfigmodel.Tsconfig.parseSync(configPath);
41
+ return _tsconfigmodel.Tsconfig.default();
42
+ }
43
+ /** First existing `tsconfig.json` on this object, if any. */ findTsConfigPath() {
44
+ return this.tsConfigPaths.find((configPath)=>HasTsConfig.fileExistsSync(configPath));
45
+ }
46
+ get tsConfigPaths() {
47
+ const paths = [
48
+ _nodepath.default.join(this.tsConfigDirectory, _const.TS_CONFIG)
49
+ ];
50
+ const fallback = this.fallbackTsConfigDirectory;
51
+ if (fallback != null) {
52
+ paths.push(_nodepath.default.join(fallback, _const.TS_CONFIG));
53
+ }
54
+ return paths;
55
+ }
56
+ static fileExistsSync(filePath) {
57
+ try {
58
+ return _nodefs.default.statSync(filePath).isFile();
59
+ } catch {
60
+ return false;
61
+ }
62
+ }
63
+ }
64
+ _ts_decorate([
65
+ (0, _caching.memoize)(),
66
+ _ts_metadata("design:type", Function),
67
+ _ts_metadata("design:paramtypes", []),
68
+ _ts_metadata("design:returntype", Promise)
69
+ ], HasTsConfig.prototype, "getTsConfig", null);
70
+ _ts_decorate([
71
+ (0, _caching.memoize)(),
72
+ _ts_metadata("design:type", Function),
73
+ _ts_metadata("design:paramtypes", []),
74
+ _ts_metadata("design:returntype", void 0)
75
+ ], HasTsConfig.prototype, "getTsConfigSync", null);