@lbdudc/linea-core 0.1.0
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 +358 -0
- package/dist/analysis/analyze.d.ts +105 -0
- package/dist/analysis/analyze.js +220 -0
- package/dist/analysis/analyze.js.map +1 -0
- package/dist/analysis/runtime.d.ts +97 -0
- package/dist/analysis/runtime.js +198 -0
- package/dist/analysis/runtime.js.map +1 -0
- package/dist/analysis/wheels/micropip-0.6.0-py3-none-any.whl +0 -0
- package/dist/analysis/wheels/packaging-23.2-py3-none-any.whl +0 -0
- package/dist/assets.d.ts +16 -0
- package/dist/assets.js +36 -0
- package/dist/assets.js.map +1 -0
- package/dist/constants.d.ts +77 -0
- package/dist/constants.js +76 -0
- package/dist/constants.js.map +1 -0
- package/dist/derivation/derive.d.ts +68 -0
- package/dist/derivation/derive.js +115 -0
- package/dist/derivation/derive.js.map +1 -0
- package/dist/derivation/engine.d.ts +48 -0
- package/dist/derivation/engine.js +98 -0
- package/dist/derivation/engine.js.map +1 -0
- package/dist/errors.d.ts +72 -0
- package/dist/errors.js +91 -0
- package/dist/errors.js.map +1 -0
- package/dist/feature-model/convert.d.ts +35 -0
- package/dist/feature-model/convert.js +47 -0
- package/dist/feature-model/convert.js.map +1 -0
- package/dist/feature-model/engine.d.ts +60 -0
- package/dist/feature-model/engine.js +139 -0
- package/dist/feature-model/engine.js.map +1 -0
- package/dist/feature-model/inspect.d.ts +67 -0
- package/dist/feature-model/inspect.js +113 -0
- package/dist/feature-model/inspect.js.map +1 -0
- package/dist/feature-model/io.d.ts +66 -0
- package/dist/feature-model/io.js +92 -0
- package/dist/feature-model/io.js.map +1 -0
- package/dist/feature-model/parse.d.ts +30 -0
- package/dist/feature-model/parse.js +36 -0
- package/dist/feature-model/parse.js.map +1 -0
- package/dist/feature-model/text.d.ts +54 -0
- package/dist/feature-model/text.js +126 -0
- package/dist/feature-model/text.js.map +1 -0
- package/dist/fs/archive.d.ts +23 -0
- package/dist/fs/archive.js +87 -0
- package/dist/fs/archive.js.map +1 -0
- package/dist/fs/diff.d.ts +40 -0
- package/dist/fs/diff.js +155 -0
- package/dist/fs/diff.js.map +1 -0
- package/dist/fs/format.d.ts +21 -0
- package/dist/fs/format.js +111 -0
- package/dist/fs/format.js.map +1 -0
- package/dist/fs/workspace.d.ts +77 -0
- package/dist/fs/workspace.js +103 -0
- package/dist/fs/workspace.js.map +1 -0
- package/dist/index.d.ts +50 -0
- package/dist/index.js +48 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/guards.d.ts +15 -0
- package/dist/internal/guards.js +16 -0
- package/dist/internal/guards.js.map +1 -0
- package/dist/line/platform-files.d.ts +73 -0
- package/dist/line/platform-files.js +112 -0
- package/dist/line/platform-files.js.map +1 -0
- package/dist/line/scaffold.d.ts +88 -0
- package/dist/line/scaffold.js +145 -0
- package/dist/line/scaffold.js.map +1 -0
- package/dist/line/templates/core/extra.js +54 -0
- package/dist/line/templates/core/transformation.js +196 -0
- package/dist/line/templates/metamodels/dataModel/extra.js +328 -0
- package/dist/line/templates/metamodels/dataModel/transformation.js +211 -0
- package/dist/line/templates/metamodels/sensor/extra.js +36 -0
- package/dist/line/templates/metamodels/sensor/transformation.js +47 -0
- package/dist/line/templates/pipeline/.gitlab-ci.yml +51 -0
- package/dist/line/templates/pipeline/ci/test-client.sh +16 -0
- package/dist/line/templates/pipeline/ci/test-server.sh +16 -0
- package/dist/product/engine-spec.d.ts +25 -0
- package/dist/product/engine-spec.js +77 -0
- package/dist/product/engine-spec.js.map +1 -0
- package/dist/product/spec.d.ts +130 -0
- package/dist/product/spec.js +219 -0
- package/dist/product/spec.js.map +1 -0
- package/dist/product/version.d.ts +27 -0
- package/dist/product/version.js +49 -0
- package/dist/product/version.js.map +1 -0
- package/dist/products-index/products-index.d.ts +224 -0
- package/dist/products-index/products-index.js +395 -0
- package/dist/products-index/products-index.js.map +1 -0
- package/dist/selection/selection.d.ts +126 -0
- package/dist/selection/selection.js +152 -0
- package/dist/selection/selection.js.map +1 -0
- package/package.json +67 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Source formatting with prettier.
|
|
3
|
+
*
|
|
4
|
+
* Migrated from `linea/server/src/model/services/utils.js:pretty` (~84):
|
|
5
|
+
* `exec('prettier --ignore-unknown --write "<path>/"')`.
|
|
6
|
+
*
|
|
7
|
+
* HARDENED PORT. The original shells out, which linea-core cannot do:
|
|
8
|
+
* - it needs a `prettier` binary on `PATH` in whatever process embeds the
|
|
9
|
+
* library, so the result depends on the host machine;
|
|
10
|
+
* - spawning a child process is exactly what ADR-014 rules out, and it would
|
|
11
|
+
* not work reliably under Bun;
|
|
12
|
+
* - the path is interpolated into a shell command string.
|
|
13
|
+
*
|
|
14
|
+
* Uses prettier's Node API instead: same formatting, no child process, works
|
|
15
|
+
* offline and under Bun. `--ignore-unknown` becomes an explicit "skip files
|
|
16
|
+
* prettier has no parser for".
|
|
17
|
+
*/
|
|
18
|
+
import fs from 'node:fs';
|
|
19
|
+
import path from 'node:path';
|
|
20
|
+
import * as prettier from 'prettier';
|
|
21
|
+
import { InvalidArgumentError } from '../errors.js';
|
|
22
|
+
/**
|
|
23
|
+
* Directories never worth walking into.
|
|
24
|
+
*
|
|
25
|
+
* DIVERGENCE from the monolith. `prettier --ignore-unknown --write "<path>/"`
|
|
26
|
+
* skips only `node_modules` by default, so the CLI would descend into `.git`,
|
|
27
|
+
* `dist`, `build`, `target` and `coverage`. Unreachable in practice — the
|
|
28
|
+
* directory being formatted is a freshly derived product, and the platform
|
|
29
|
+
* `config.json` already excludes `build`/`target`/`bin` from derivation — but
|
|
30
|
+
* recorded here because every other divergence in this file is.
|
|
31
|
+
*/
|
|
32
|
+
const SKIP_DIRECTORIES = new Set(['node_modules', '.git', 'dist', 'build', 'target', 'coverage']);
|
|
33
|
+
/** Every file under `dir`, recursively, as absolute paths. */
|
|
34
|
+
const listFiles = (dir) => {
|
|
35
|
+
const found = [];
|
|
36
|
+
const walk = (current) => {
|
|
37
|
+
let entries;
|
|
38
|
+
try {
|
|
39
|
+
entries = fs.readdirSync(current, { withFileTypes: true });
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
for (const entry of entries) {
|
|
45
|
+
const absolute = path.join(current, entry.name);
|
|
46
|
+
if (entry.isDirectory()) {
|
|
47
|
+
if (SKIP_DIRECTORIES.has(entry.name))
|
|
48
|
+
continue;
|
|
49
|
+
walk(absolute);
|
|
50
|
+
}
|
|
51
|
+
else if (entry.isFile()) {
|
|
52
|
+
found.push(absolute);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
walk(dir);
|
|
57
|
+
return found.sort();
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Formats every file prettier understands under a directory, in place.
|
|
61
|
+
*
|
|
62
|
+
* Files with no inferable parser are skipped, which is what `--ignore-unknown`
|
|
63
|
+
* does. Files that prettier cannot parse (a syntax error in generated code, say)
|
|
64
|
+
* are skipped too rather than aborting the whole run: formatting is cosmetic and
|
|
65
|
+
* must never fail a generation.
|
|
66
|
+
*
|
|
67
|
+
* Idempotent by construction, since prettier output is a fixed point. A file is
|
|
68
|
+
* only rewritten when its content actually changes, so mtimes stay put and the
|
|
69
|
+
* directory diff does not gain spurious entries.
|
|
70
|
+
*
|
|
71
|
+
* @param params.dir Directory to format, in place.
|
|
72
|
+
* @returns How many files were rewritten.
|
|
73
|
+
* @throws {InvalidArgumentError} when `dir` is not a non-empty existing directory.
|
|
74
|
+
*/
|
|
75
|
+
export const formatDirectory = async ({ dir }) => {
|
|
76
|
+
if (typeof dir !== 'string' || dir.trim() === '') {
|
|
77
|
+
throw new InvalidArgumentError('"dir" must be a non-empty path.');
|
|
78
|
+
}
|
|
79
|
+
const root = path.resolve(dir);
|
|
80
|
+
if (!fs.existsSync(root) || !fs.statSync(root).isDirectory()) {
|
|
81
|
+
throw new InvalidArgumentError(`Not a directory: ${root}`);
|
|
82
|
+
}
|
|
83
|
+
let formatted = 0;
|
|
84
|
+
for (const filePath of listFiles(root)) {
|
|
85
|
+
try {
|
|
86
|
+
const { inferredParser } = await prettier.getFileInfo(filePath, { resolveConfig: false });
|
|
87
|
+
// Equivalent of `--ignore-unknown`: no parser, no formatting.
|
|
88
|
+
if (inferredParser === null)
|
|
89
|
+
continue;
|
|
90
|
+
// Resolved PER FILE, like the prettier CLI, so a nested `.prettierrc`
|
|
91
|
+
// applies to its own subtree. Resolving once from the root would also miss
|
|
92
|
+
// a config living IN the root: `resolveConfig` searches upward from
|
|
93
|
+
// `path.dirname(target)`, which for a directory is its parent.
|
|
94
|
+
// prettier caches these lookups internally, so this stays cheap.
|
|
95
|
+
const options = await prettier.resolveConfig(filePath);
|
|
96
|
+
const original = fs.readFileSync(filePath, 'utf8');
|
|
97
|
+
const output = await prettier.format(original, { ...options, filepath: filePath });
|
|
98
|
+
if (output !== original) {
|
|
99
|
+
fs.writeFileSync(filePath, output, 'utf8');
|
|
100
|
+
formatted += 1;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
// One file failing — unparseable, unreadable, vanished mid-walk — must
|
|
105
|
+
// never abort the run. Formatting is cosmetic; leave it as it was.
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return { formatted };
|
|
110
|
+
};
|
|
111
|
+
//# sourceMappingURL=format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.js","sourceRoot":"","sources":["../../src/fs/format.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,KAAK,QAAQ,MAAM,UAAU,CAAA;AACpC,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AAEnD;;;;;;;;;GASG;AACH,MAAM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,CAAC;IACH,CAAC;IAED,OAAO,EAAE,SAAS,EAAE,CAAA;AACtB,CAAC,CAAA","sourcesContent":["/**\r\n * Source formatting with prettier.\r\n *\r\n * Migrated from `linea/server/src/model/services/utils.js:pretty` (~84):\r\n * `exec('prettier --ignore-unknown --write \"<path>/\"')`.\r\n *\r\n * HARDENED PORT. The original shells out, which linea-core cannot do:\r\n * - it needs a `prettier` binary on `PATH` in whatever process embeds the\r\n * library, so the result depends on the host machine;\r\n * - spawning a child process is exactly what ADR-014 rules out, and it would\r\n * not work reliably under Bun;\r\n * - the path is interpolated into a shell command string.\r\n *\r\n * Uses prettier's Node API instead: same formatting, no child process, works\r\n * offline and under Bun. `--ignore-unknown` becomes an explicit \"skip files\r\n * prettier has no parser for\".\r\n */\r\nimport fs from 'node:fs'\r\nimport path from 'node:path'\r\nimport * as prettier from 'prettier'\r\nimport { InvalidArgumentError } from '../errors.js'\r\n\r\n/**\r\n * Directories never worth walking into.\r\n *\r\n * DIVERGENCE from the monolith. `prettier --ignore-unknown --write \"<path>/\"`\r\n * skips only `node_modules` by default, so the CLI would descend into `.git`,\r\n * `dist`, `build`, `target` and `coverage`. Unreachable in practice — the\r\n * directory being formatted is a freshly derived product, and the platform\r\n * `config.json` already excludes `build`/`target`/`bin` from derivation — but\r\n * recorded here because every other divergence in this file is.\r\n */\r\nconst SKIP_DIRECTORIES = new Set(['node_modules', '.git', 'dist', 'build', 'target', 'coverage'])\r\n\r\n/** Every file under `dir`, recursively, as absolute paths. */\r\nconst listFiles = (dir: string): string[] => {\r\n const found: string[] = []\r\n const walk = (current: string): void => {\r\n let entries: fs.Dirent[]\r\n try {\r\n entries = fs.readdirSync(current, { withFileTypes: true })\r\n } catch {\r\n return\r\n }\r\n for (const entry of entries) {\r\n const absolute = path.join(current, entry.name)\r\n if (entry.isDirectory()) {\r\n if (SKIP_DIRECTORIES.has(entry.name)) continue\r\n walk(absolute)\r\n } else if (entry.isFile()) {\r\n found.push(absolute)\r\n }\r\n }\r\n }\r\n walk(dir)\r\n return found.sort()\r\n}\r\n\r\n/**\r\n * Formats every file prettier understands under a directory, in place.\r\n *\r\n * Files with no inferable parser are skipped, which is what `--ignore-unknown`\r\n * does. Files that prettier cannot parse (a syntax error in generated code, say)\r\n * are skipped too rather than aborting the whole run: formatting is cosmetic and\r\n * must never fail a generation.\r\n *\r\n * Idempotent by construction, since prettier output is a fixed point. A file is\r\n * only rewritten when its content actually changes, so mtimes stay put and the\r\n * directory diff does not gain spurious entries.\r\n *\r\n * @param params.dir Directory to format, in place.\r\n * @returns How many files were rewritten.\r\n * @throws {InvalidArgumentError} when `dir` is not a non-empty existing directory.\r\n */\r\nexport const formatDirectory = async ({ dir }: { dir: string }): Promise<{ formatted: number }> => {\r\n if (typeof dir !== 'string' || dir.trim() === '') {\r\n throw new InvalidArgumentError('\"dir\" must be a non-empty path.')\r\n }\r\n const root = path.resolve(dir)\r\n if (!fs.existsSync(root) || !fs.statSync(root).isDirectory()) {\r\n throw new InvalidArgumentError(`Not a directory: ${root}`)\r\n }\r\n\r\n let formatted = 0\r\n for (const filePath of listFiles(root)) {\r\n try {\r\n const { inferredParser } = await prettier.getFileInfo(filePath, { resolveConfig: false })\r\n // Equivalent of `--ignore-unknown`: no parser, no formatting.\r\n if (inferredParser === null) continue\r\n\r\n // Resolved PER FILE, like the prettier CLI, so a nested `.prettierrc`\r\n // applies to its own subtree. Resolving once from the root would also miss\r\n // a config living IN the root: `resolveConfig` searches upward from\r\n // `path.dirname(target)`, which for a directory is its parent.\r\n // prettier caches these lookups internally, so this stays cheap.\r\n const options = await prettier.resolveConfig(filePath)\r\n const original = fs.readFileSync(filePath, 'utf8')\r\n const output = await prettier.format(original, { ...options, filepath: filePath })\r\n if (output !== original) {\r\n fs.writeFileSync(filePath, output, 'utf8')\r\n formatted += 1\r\n }\r\n } catch {\r\n // One file failing — unparseable, unreadable, vanished mid-walk — must\r\n // never abort the run. Formatting is cosmetic; leave it as it was.\r\n continue\r\n }\r\n }\r\n\r\n return { formatted }\r\n}\r\n"]}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/** Absolute paths of the well-known files of a line working directory. */
|
|
2
|
+
export interface LinePaths {
|
|
3
|
+
/** The `src/platform` directory. */
|
|
4
|
+
readonly platform: string;
|
|
5
|
+
/** Annotated source consumed by the derivation engine. */
|
|
6
|
+
readonly code: string;
|
|
7
|
+
/** UVL feature model. The XML variant lives at `PLATFORM_PATHS.modelXml`. */
|
|
8
|
+
readonly model: string;
|
|
9
|
+
/** Engine configuration (`config.json`). */
|
|
10
|
+
readonly config: string;
|
|
11
|
+
/** Template helper functions (`extra.js`). */
|
|
12
|
+
readonly extraJs: string;
|
|
13
|
+
/** Spec transformation function (`transformation.js`). */
|
|
14
|
+
readonly transformation: string;
|
|
15
|
+
/** Product index at the repository root (ADR-011). */
|
|
16
|
+
readonly productsIndex: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Resolves the well-known paths of a line working directory.
|
|
20
|
+
*
|
|
21
|
+
* The layout mirrors `linea/server/src/resources/properties.yml`
|
|
22
|
+
* (`paths.platform.*`), which the monolith read through `properties.paths` in
|
|
23
|
+
* `services/utils.js:engine()`. Purely a path computation: nothing is read and
|
|
24
|
+
* nothing is required to exist.
|
|
25
|
+
*
|
|
26
|
+
* @param params.lineDir Root of the line working directory (its repository root).
|
|
27
|
+
* @returns Absolute paths for every well-known file.
|
|
28
|
+
* @throws {InvalidArgumentError} if `lineDir` is not a non-empty string.
|
|
29
|
+
*/
|
|
30
|
+
export declare const resolveLinePaths: ({ lineDir }: {
|
|
31
|
+
lineDir: string;
|
|
32
|
+
}) => LinePaths;
|
|
33
|
+
/**
|
|
34
|
+
* Creates a directory and its parents if they do not exist. Idempotent.
|
|
35
|
+
*
|
|
36
|
+
* @param params.dirPath Directory to create.
|
|
37
|
+
* @returns The absolute path of the directory.
|
|
38
|
+
* @throws {InvalidArgumentError} if `dirPath` is not a non-empty string.
|
|
39
|
+
*/
|
|
40
|
+
export declare const ensureDir: ({ dirPath }: {
|
|
41
|
+
dirPath: string;
|
|
42
|
+
}) => string;
|
|
43
|
+
/**
|
|
44
|
+
* Reads a UTF-8 text file.
|
|
45
|
+
*
|
|
46
|
+
* Unlike the monolith there is no base64 step: models and platform files are
|
|
47
|
+
* plain text on disk. Decoding what the GitLab API returns is linea-server's job.
|
|
48
|
+
*
|
|
49
|
+
* @param params.filePath File to read.
|
|
50
|
+
* @returns The file contents.
|
|
51
|
+
* @throws {InvalidArgumentError} if `filePath` is not a non-empty string.
|
|
52
|
+
*/
|
|
53
|
+
export declare const readTextFile: ({ filePath }: {
|
|
54
|
+
filePath: string;
|
|
55
|
+
}) => string;
|
|
56
|
+
/**
|
|
57
|
+
* Writes a UTF-8 text file, creating parent directories as needed.
|
|
58
|
+
*
|
|
59
|
+
* @param params.filePath File to write.
|
|
60
|
+
* @param params.content Contents to write verbatim (no trailing newline is added).
|
|
61
|
+
* @returns The absolute path written.
|
|
62
|
+
* @throws {InvalidArgumentError} if the arguments are not strings.
|
|
63
|
+
*/
|
|
64
|
+
export declare const writeTextFile: ({ filePath, content }: {
|
|
65
|
+
filePath: string;
|
|
66
|
+
content: string;
|
|
67
|
+
}) => string;
|
|
68
|
+
/**
|
|
69
|
+
* Whether `filePath` exists and is a regular file.
|
|
70
|
+
*
|
|
71
|
+
* @param params.filePath Path to probe.
|
|
72
|
+
* @returns `true` only for an existing regular file.
|
|
73
|
+
* @throws {InvalidArgumentError} if `filePath` is not a non-empty string.
|
|
74
|
+
*/
|
|
75
|
+
export declare const fileExists: ({ filePath }: {
|
|
76
|
+
filePath: string;
|
|
77
|
+
}) => boolean;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Filesystem helpers over a line working directory.
|
|
3
|
+
*
|
|
4
|
+
* ADR-009: linea-core owns no database. It operates on directories the caller
|
|
5
|
+
* hands it (a clone or an unzipped export of a line repository) and returns
|
|
6
|
+
* explicit results. Every function takes its working directory as a parameter;
|
|
7
|
+
* nothing is resolved from `process.cwd()` or the environment (ADR-014).
|
|
8
|
+
*
|
|
9
|
+
* Like the rest of the public API, every function takes a single named-parameter
|
|
10
|
+
* object — even the single-argument ones. Consistency of the contract consumed
|
|
11
|
+
* by linea-server and linea-cli beats brevity.
|
|
12
|
+
*/
|
|
13
|
+
import fs from 'node:fs';
|
|
14
|
+
import path from 'node:path';
|
|
15
|
+
import { PLATFORM_PATHS, PRODUCTS_INDEX_PATH } from '../constants.js';
|
|
16
|
+
import { InvalidArgumentError } from '../errors.js';
|
|
17
|
+
const assertPath = (value, parameter) => {
|
|
18
|
+
if (typeof value !== 'string' || value.trim() === '') {
|
|
19
|
+
throw new InvalidArgumentError(`"${parameter}" must be a non-empty path.`);
|
|
20
|
+
}
|
|
21
|
+
return path.resolve(value);
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Resolves the well-known paths of a line working directory.
|
|
25
|
+
*
|
|
26
|
+
* The layout mirrors `linea/server/src/resources/properties.yml`
|
|
27
|
+
* (`paths.platform.*`), which the monolith read through `properties.paths` in
|
|
28
|
+
* `services/utils.js:engine()`. Purely a path computation: nothing is read and
|
|
29
|
+
* nothing is required to exist.
|
|
30
|
+
*
|
|
31
|
+
* @param params.lineDir Root of the line working directory (its repository root).
|
|
32
|
+
* @returns Absolute paths for every well-known file.
|
|
33
|
+
* @throws {InvalidArgumentError} if `lineDir` is not a non-empty string.
|
|
34
|
+
*/
|
|
35
|
+
export const resolveLinePaths = ({ lineDir }) => {
|
|
36
|
+
const root = assertPath(lineDir, 'lineDir');
|
|
37
|
+
return {
|
|
38
|
+
platform: path.join(root, PLATFORM_PATHS.root),
|
|
39
|
+
code: path.join(root, PLATFORM_PATHS.code),
|
|
40
|
+
model: path.join(root, PLATFORM_PATHS.model),
|
|
41
|
+
config: path.join(root, PLATFORM_PATHS.config),
|
|
42
|
+
extraJs: path.join(root, PLATFORM_PATHS.extraJs),
|
|
43
|
+
transformation: path.join(root, PLATFORM_PATHS.transformation),
|
|
44
|
+
productsIndex: path.join(root, PRODUCTS_INDEX_PATH)
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Creates a directory and its parents if they do not exist. Idempotent.
|
|
49
|
+
*
|
|
50
|
+
* @param params.dirPath Directory to create.
|
|
51
|
+
* @returns The absolute path of the directory.
|
|
52
|
+
* @throws {InvalidArgumentError} if `dirPath` is not a non-empty string.
|
|
53
|
+
*/
|
|
54
|
+
export const ensureDir = ({ dirPath }) => {
|
|
55
|
+
const absolute = assertPath(dirPath, 'dirPath');
|
|
56
|
+
fs.mkdirSync(absolute, { recursive: true });
|
|
57
|
+
return absolute;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Reads a UTF-8 text file.
|
|
61
|
+
*
|
|
62
|
+
* Unlike the monolith there is no base64 step: models and platform files are
|
|
63
|
+
* plain text on disk. Decoding what the GitLab API returns is linea-server's job.
|
|
64
|
+
*
|
|
65
|
+
* @param params.filePath File to read.
|
|
66
|
+
* @returns The file contents.
|
|
67
|
+
* @throws {InvalidArgumentError} if `filePath` is not a non-empty string.
|
|
68
|
+
*/
|
|
69
|
+
export const readTextFile = ({ filePath }) => fs.readFileSync(assertPath(filePath, 'filePath'), 'utf8');
|
|
70
|
+
/**
|
|
71
|
+
* Writes a UTF-8 text file, creating parent directories as needed.
|
|
72
|
+
*
|
|
73
|
+
* @param params.filePath File to write.
|
|
74
|
+
* @param params.content Contents to write verbatim (no trailing newline is added).
|
|
75
|
+
* @returns The absolute path written.
|
|
76
|
+
* @throws {InvalidArgumentError} if the arguments are not strings.
|
|
77
|
+
*/
|
|
78
|
+
export const writeTextFile = ({ filePath, content }) => {
|
|
79
|
+
const absolute = assertPath(filePath, 'filePath');
|
|
80
|
+
if (typeof content !== 'string') {
|
|
81
|
+
throw new InvalidArgumentError('"content" must be a string.');
|
|
82
|
+
}
|
|
83
|
+
ensureDir({ dirPath: path.dirname(absolute) });
|
|
84
|
+
fs.writeFileSync(absolute, content, 'utf8');
|
|
85
|
+
return absolute;
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Whether `filePath` exists and is a regular file.
|
|
89
|
+
*
|
|
90
|
+
* @param params.filePath Path to probe.
|
|
91
|
+
* @returns `true` only for an existing regular file.
|
|
92
|
+
* @throws {InvalidArgumentError} if `filePath` is not a non-empty string.
|
|
93
|
+
*/
|
|
94
|
+
export const fileExists = ({ filePath }) => {
|
|
95
|
+
const absolute = assertPath(filePath, 'filePath');
|
|
96
|
+
try {
|
|
97
|
+
return fs.statSync(absolute).isFile();
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
//# sourceMappingURL=workspace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workspace.js","sourceRoot":"","sources":["../../src/fs/workspace.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AACrE,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AAoBnD,MAAM,UAAU,GAAG,CAAC,KAAc,EAAE,SAAiB,EAAU,EAAE;IAC/D,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QACrD,MAAM,IAAI,oBAAoB,CAAC,IAAI,SAAS,6BAA6B,CAAC,CAAA;IAC5E,CAAC;IACD,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;AAC5B,CAAC,CAAA;AAED;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,EAAE,OAAO,EAAuB,EAAa,EAAE;IAC9E,MAAM,IAAI,GAAG,UAAU,CAAC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AQ,EAAE,UAAU,CAAC,CAAA;IACjD,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAChC,MAAM,IAAI,oBAAoB,CAAC,6BAA6B,CAAC,CAAA;IAC/D,CAAC;IACD,SAAS,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;IAC9C,EAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,OAAO,EAAE,MAAM,CAAC,CAAA;IAC3C,OAAO,QAAQ,CAAA;AACjB,CAAC,CAAA;AAED;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,EAAE,QAAQ,EAAwB,EAAW,EAAE;IACxE,MAAM,QAAQ,GAAG,UAAU,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAA;IACjD,IAAI,CAAC;QACH,OAAO,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,MAAM,EAAE,CAAA;IACvC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC,CAAA","sourcesContent":["/**\r\n * Filesystem helpers over a line working directory.\r\n *\r\n * ADR-009: linea-core owns no database. It operates on directories the caller\r\n * hands it (a clone or an unzipped export of a line repository) and returns\r\n * explicit results. Every function takes its working directory as a parameter;\r\n * nothing is resolved from `process.cwd()` or the environment (ADR-014).\r\n *\r\n * Like the rest of the public API, every function takes a single named-parameter\r\n * object — even the single-argument ones. Consistency of the contract consumed\r\n * by linea-server and linea-cli beats brevity.\r\n */\r\nimport fs from 'node:fs'\r\nimport path from 'node:path'\r\nimport { PLATFORM_PATHS, PRODUCTS_INDEX_PATH } from '../constants.js'\r\nimport { InvalidArgumentError } from '../errors.js'\r\n\r\n/** Absolute paths of the well-known files of a line working directory. */\r\nexport interface LinePaths {\r\n /** The `src/platform` directory. */\r\n readonly platform: string\r\n /** Annotated source consumed by the derivation engine. */\r\n readonly code: string\r\n /** UVL feature model. The XML variant lives at `PLATFORM_PATHS.modelXml`. */\r\n readonly model: string\r\n /** Engine configuration (`config.json`). */\r\n readonly config: string\r\n /** Template helper functions (`extra.js`). */\r\n readonly extraJs: string\r\n /** Spec transformation function (`transformation.js`). */\r\n readonly transformation: string\r\n /** Product index at the repository root (ADR-011). */\r\n readonly productsIndex: string\r\n}\r\n\r\nconst assertPath = (value: unknown, parameter: string): string => {\r\n if (typeof value !== 'string' || value.trim() === '') {\r\n throw new InvalidArgumentError(`\"${parameter}\" must be a non-empty path.`)\r\n }\r\n return path.resolve(value)\r\n}\r\n\r\n/**\r\n * Resolves the well-known paths of a line working directory.\r\n *\r\n * The layout mirrors `linea/server/src/resources/properties.yml`\r\n * (`paths.platform.*`), which the monolith read through `properties.paths` in\r\n * `services/utils.js:engine()`. Purely a path computation: nothing is read and\r\n * nothing is required to exist.\r\n *\r\n * @param params.lineDir Root of the line working directory (its repository root).\r\n * @returns Absolute paths for every well-known file.\r\n * @throws {InvalidArgumentError} if `lineDir` is not a non-empty string.\r\n */\r\nexport const resolveLinePaths = ({ lineDir }: { lineDir: string }): LinePaths => {\r\n const root = assertPath(lineDir, 'lineDir')\r\n return {\r\n platform: path.join(root, PLATFORM_PATHS.root),\r\n code: path.join(root, PLATFORM_PATHS.code),\r\n model: path.join(root, PLATFORM_PATHS.model),\r\n config: path.join(root, PLATFORM_PATHS.config),\r\n extraJs: path.join(root, PLATFORM_PATHS.extraJs),\r\n transformation: path.join(root, PLATFORM_PATHS.transformation),\r\n productsIndex: path.join(root, PRODUCTS_INDEX_PATH)\r\n }\r\n}\r\n\r\n/**\r\n * Creates a directory and its parents if they do not exist. Idempotent.\r\n *\r\n * @param params.dirPath Directory to create.\r\n * @returns The absolute path of the directory.\r\n * @throws {InvalidArgumentError} if `dirPath` is not a non-empty string.\r\n */\r\nexport const ensureDir = ({ dirPath }: { dirPath: string }): string => {\r\n const absolute = assertPath(dirPath, 'dirPath')\r\n fs.mkdirSync(absolute, { recursive: true })\r\n return absolute\r\n}\r\n\r\n/**\r\n * Reads a UTF-8 text file.\r\n *\r\n * Unlike the monolith there is no base64 step: models and platform files are\r\n * plain text on disk. Decoding what the GitLab API returns is linea-server's job.\r\n *\r\n * @param params.filePath File to read.\r\n * @returns The file contents.\r\n * @throws {InvalidArgumentError} if `filePath` is not a non-empty string.\r\n */\r\nexport const readTextFile = ({ filePath }: { filePath: string }): string =>\r\n fs.readFileSync(assertPath(filePath, 'filePath'), 'utf8')\r\n\r\n/**\r\n * Writes a UTF-8 text file, creating parent directories as needed.\r\n *\r\n * @param params.filePath File to write.\r\n * @param params.content Contents to write verbatim (no trailing newline is added).\r\n * @returns The absolute path written.\r\n * @throws {InvalidArgumentError} if the arguments are not strings.\r\n */\r\nexport const writeTextFile = ({\r\n filePath,\r\n content\r\n}: {\r\n filePath: string\r\n content: string\r\n}): string => {\r\n const absolute = assertPath(filePath, 'filePath')\r\n if (typeof content !== 'string') {\r\n throw new InvalidArgumentError('\"content\" must be a string.')\r\n }\r\n ensureDir({ dirPath: path.dirname(absolute) })\r\n fs.writeFileSync(absolute, content, 'utf8')\r\n return absolute\r\n}\r\n\r\n/**\r\n * Whether `filePath` exists and is a regular file.\r\n *\r\n * @param params.filePath Path to probe.\r\n * @returns `true` only for an existing regular file.\r\n * @throws {InvalidArgumentError} if `filePath` is not a non-empty string.\r\n */\r\nexport const fileExists = ({ filePath }: { filePath: string }): boolean => {\r\n const absolute = assertPath(filePath, 'filePath')\r\n try {\r\n return fs.statSync(absolute).isFile()\r\n } catch {\r\n return false\r\n }\r\n}\r\n"]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* linea-core — offline engine for Software Product Lines.
|
|
3
|
+
*
|
|
4
|
+
* A library of stateless JavaScript functions (ADR-014): every function receives
|
|
5
|
+
* what it needs as parameters and returns explicit results. No internal state,
|
|
6
|
+
* no singletons, no dependency injection, no global configuration, no database
|
|
7
|
+
* and no network (ADR-002). Side effects are limited to the directories the
|
|
8
|
+
* caller points at (ADR-009).
|
|
9
|
+
*
|
|
10
|
+
* This is the ONLY public entry point. Everything under `src/` other than this
|
|
11
|
+
* file is private and may change without notice — the `exports` map exposes a
|
|
12
|
+
* single entry on purpose.
|
|
13
|
+
*/
|
|
14
|
+
export { PLATFORM_PATHS, PRODUCTS_INDEX_PATH, NAME_PATTERN, VERSION_PATTERN, DEFAULT_LANGUAGES, DEFAULT_SRID, FEATURE_MODEL_TYPES, ANALYSIS_THRESHOLDS, isFeatureModelType } from './constants.js';
|
|
15
|
+
export type { FeatureModelType } from './constants.js';
|
|
16
|
+
export { LineaCoreError, InvalidArgumentError, UvlParseError, UnsupportedConversionError, FeatureSelectionInvalidError, LinePlatformNotFoundError, InvalidProductSpecError, ProductsIndexError, AnalysisRuntimeError } from './errors.js';
|
|
17
|
+
export type { LineaCoreErrorCode } from './errors.js';
|
|
18
|
+
export { parseFeatureModel } from './feature-model/parse.js';
|
|
19
|
+
export type { FeatureModelValue } from './feature-model/parse.js';
|
|
20
|
+
export { convertFeatureModel } from './feature-model/convert.js';
|
|
21
|
+
export { detectFeatureModelType, readFeatureModel, writeFeatureModel } from './feature-model/io.js';
|
|
22
|
+
export type { FeatureModelLocation } from './feature-model/io.js';
|
|
23
|
+
export { normalizeUvl, estimateFeatureCount, emptyFeatureModelUvl } from './feature-model/text.js';
|
|
24
|
+
export { extractFeatureNames, computeMandatoryFeatures } from './feature-model/inspect.js';
|
|
25
|
+
export type { MandatoryFeaturesResult } from './feature-model/inspect.js';
|
|
26
|
+
export { normalizeFeatureSelection, validateFeatureSelection, assertFeatureSelection, validateModelAgainstSelections } from './selection/selection.js';
|
|
27
|
+
export type { FeatureSelectionInput, SelectionBearingSpec, FeatureSelectionVerdict, NamedSelection, BrokenSelection, ModelAgainstSelectionsVerdict } from './selection/selection.js';
|
|
28
|
+
export { validateProductSpec, assertProductSpec, normalizeProductSpec } from './product/spec.js';
|
|
29
|
+
export type { ProductSpec, ProductBasicData, ProductSpecError, ProductSpecErrorCode, ProductSpecValidation } from './product/spec.js';
|
|
30
|
+
export { incrementVersion } from './product/version.js';
|
|
31
|
+
export { buildEngineSpec } from './product/engine-spec.js';
|
|
32
|
+
export type { EngineSpec } from './product/engine-spec.js';
|
|
33
|
+
export { emptyProductsIndex, parseProductsIndex, serializeProductsIndex, validateProductsIndex, addProductToIndex, renameProductInIndex, removeProductFromIndex, readProductsIndex, writeProductsIndex, reconcileProductsIndex } from './products-index/products-index.js';
|
|
34
|
+
export type { ProductsIndex, ProductsIndexEntry, ProductsIndexProblem, ProductsIndexProblemCode, ProductsIndexValidation, ProductsIndexReconciliation } from './products-index/products-index.js';
|
|
35
|
+
export { buildLineScaffold, writeLineScaffold, DEFAULT_PLATFORM_CONFIG, DEFAULT_CODE_GITIGNORE } from './line/scaffold.js';
|
|
36
|
+
export type { LineScaffoldInput } from './line/scaffold.js';
|
|
37
|
+
export { buildExtraJs, buildTransformationJs, getPipelineFiles } from './line/platform-files.js';
|
|
38
|
+
export type { FileSpec, MetamodelName } from './line/platform-files.js';
|
|
39
|
+
export { createAnalysisRuntime, disposeAnalysisRuntime } from './analysis/runtime.js';
|
|
40
|
+
export type { AnalysisRuntime, AnalysisRuntimeOptions } from './analysis/runtime.js';
|
|
41
|
+
export { analyzeFeatureModel, analyzeFeatureModelBdd, analyzeMetric, ANALYSIS_METRICS } from './analysis/analyze.js';
|
|
42
|
+
export type { AnalysisMode, AnalysisMetric, FeatureModelAnalysis, FeatureModelBddAnalysis, MetricAnalysis } from './analysis/analyze.js';
|
|
43
|
+
export { deriveProduct, deriveProductToZip } from './derivation/derive.js';
|
|
44
|
+
export { extractArchive } from './fs/archive.js';
|
|
45
|
+
export { diffDirectories } from './fs/diff.js';
|
|
46
|
+
export type { FileChange } from './fs/diff.js';
|
|
47
|
+
export { formatDirectory } from './fs/format.js';
|
|
48
|
+
export { resolveLinePaths, ensureDir, readTextFile, writeTextFile, fileExists } from './fs/workspace.js';
|
|
49
|
+
export type { LinePaths } from './fs/workspace.js';
|
|
50
|
+
export { resolveAsset, assetsRoot } from './assets.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* linea-core — offline engine for Software Product Lines.
|
|
3
|
+
*
|
|
4
|
+
* A library of stateless JavaScript functions (ADR-014): every function receives
|
|
5
|
+
* what it needs as parameters and returns explicit results. No internal state,
|
|
6
|
+
* no singletons, no dependency injection, no global configuration, no database
|
|
7
|
+
* and no network (ADR-002). Side effects are limited to the directories the
|
|
8
|
+
* caller points at (ADR-009).
|
|
9
|
+
*
|
|
10
|
+
* This is the ONLY public entry point. Everything under `src/` other than this
|
|
11
|
+
* file is private and may change without notice — the `exports` map exposes a
|
|
12
|
+
* single entry on purpose.
|
|
13
|
+
*/
|
|
14
|
+
// ── Constants ────────────────────────────────────────────────────────────────
|
|
15
|
+
export { PLATFORM_PATHS, PRODUCTS_INDEX_PATH, NAME_PATTERN, VERSION_PATTERN, DEFAULT_LANGUAGES, DEFAULT_SRID, FEATURE_MODEL_TYPES, ANALYSIS_THRESHOLDS, isFeatureModelType } from './constants.js';
|
|
16
|
+
// ── Errors ───────────────────────────────────────────────────────────────────
|
|
17
|
+
export { LineaCoreError, InvalidArgumentError, UvlParseError, UnsupportedConversionError, FeatureSelectionInvalidError, LinePlatformNotFoundError, InvalidProductSpecError, ProductsIndexError, AnalysisRuntimeError } from './errors.js';
|
|
18
|
+
// ── Feature models ───────────────────────────────────────────────────────────
|
|
19
|
+
export { parseFeatureModel } from './feature-model/parse.js';
|
|
20
|
+
export { convertFeatureModel } from './feature-model/convert.js';
|
|
21
|
+
export { detectFeatureModelType, readFeatureModel, writeFeatureModel } from './feature-model/io.js';
|
|
22
|
+
export { normalizeUvl, estimateFeatureCount, emptyFeatureModelUvl } from './feature-model/text.js';
|
|
23
|
+
export { extractFeatureNames, computeMandatoryFeatures } from './feature-model/inspect.js';
|
|
24
|
+
// ── Feature selection ────────────────────────────────────────────────────────
|
|
25
|
+
export { normalizeFeatureSelection, validateFeatureSelection, assertFeatureSelection, validateModelAgainstSelections } from './selection/selection.js';
|
|
26
|
+
// ── Product specs ────────────────────────────────────────────────────────────
|
|
27
|
+
export { validateProductSpec, assertProductSpec, normalizeProductSpec } from './product/spec.js';
|
|
28
|
+
export { incrementVersion } from './product/version.js';
|
|
29
|
+
export { buildEngineSpec } from './product/engine-spec.js';
|
|
30
|
+
// ── Products index (ADR-011) ─────────────────────────────────────────────────
|
|
31
|
+
export { emptyProductsIndex, parseProductsIndex, serializeProductsIndex, validateProductsIndex, addProductToIndex, renameProductInIndex, removeProductFromIndex, readProductsIndex, writeProductsIndex, reconcileProductsIndex } from './products-index/products-index.js';
|
|
32
|
+
// ── Line scaffold and platform files ─────────────────────────────────────────
|
|
33
|
+
export { buildLineScaffold, writeLineScaffold, DEFAULT_PLATFORM_CONFIG, DEFAULT_CODE_GITIGNORE } from './line/scaffold.js';
|
|
34
|
+
export { buildExtraJs, buildTransformationJs, getPipelineFiles } from './line/platform-files.js';
|
|
35
|
+
// ── Feature model analysis (ADR-008, ADR-021) ────────────────────────────────
|
|
36
|
+
export { createAnalysisRuntime, disposeAnalysisRuntime } from './analysis/runtime.js';
|
|
37
|
+
export { analyzeFeatureModel, analyzeFeatureModelBdd, analyzeMetric, ANALYSIS_METRICS } from './analysis/analyze.js';
|
|
38
|
+
// ── Product derivation ───────────────────────────────────────────────────────
|
|
39
|
+
export { deriveProduct, deriveProductToZip } from './derivation/derive.js';
|
|
40
|
+
// ── Archive, diff and formatting ─────────────────────────────────────────────
|
|
41
|
+
export { extractArchive } from './fs/archive.js';
|
|
42
|
+
export { diffDirectories } from './fs/diff.js';
|
|
43
|
+
export { formatDirectory } from './fs/format.js';
|
|
44
|
+
// ── Working directories ──────────────────────────────────────────────────────
|
|
45
|
+
export { resolveLinePaths, ensureDir, readTextFile, writeTextFile, fileExists } from './fs/workspace.js';
|
|
46
|
+
// ── Packaged assets ──────────────────────────────────────────────────────────
|
|
47
|
+
export { resolveAsset, assetsRoot } from './assets.js';
|
|
48
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,gFAAgF;AAChF,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,YAAY,EACZ,eAAe,EACf,iBAAiB,EACjB,YAAY,EACZ,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EACnB,MAAM,gBAAgB,CAAA;AAGvB,gFAAgF;AAChF,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,aAAa,EACb,0BAA0B,EAC1B,4BAA4B,EAC5B,yBAAyB,EACzB,uBAAuB,EACvB,kBAAkB,EAClB,oBAAoB,EACrB,MAAM,aAAa,CAAA;AAGpB,gFAAgF;AAChF,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAE5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAA;AAChE,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AAEnG,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAClG,OAAO,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAA;AAG1F,gFAAgF;AAChF,OAAO,EACL,yBAAyB,EACzB,wBAAwB,EACxB,sBAAsB,EACtB,8BAA8B,EAC/B,MAAM,0BAA0B,CAAA;AAUjC,gFAAgF;AAChF,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAA;AAQhG,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAG1D,gFAAgF;AAChF,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,sBAAsB,EACtB,qBAAqB,EACrB,iBAAiB,EACjB,oBAAoB,EACpB,sBAAsB,EACtB,iBAAiB,EACjB,kBAAkB,EAClB,sBAAsB,EACvB,MAAM,oCAAoC,CAAA;AAU3C,gFAAgF;AAChF,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,uBAAuB,EACvB,sBAAsB,EACvB,MAAM,oBAAoB,CAAA;AAE3B,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAA;AAGhG,gFAAgF;AAChF,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAA;AAErF,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EACtB,aAAa,EACb,gBAAgB,EACjB,MAAM,uBAAuB,CAAA;AAS9B,gFAAgF;AAChF,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAE1E,gFAAgF;AAChF,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAE9C,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAEhD,gFAAgF;AAChF,OAAO,EACL,gBAAgB,EAChB,SAAS,EACT,YAAY,EACZ,aAAa,EACb,UAAU,EACX,MAAM,mBAAmB,CAAA;AAG1B,gFAAgF;AAChF,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA","sourcesContent":["/**\r\n * linea-core — offline engine for Software Product Lines.\r\n *\r\n * A library of stateless JavaScript functions (ADR-014): every function receives\r\n * what it needs as parameters and returns explicit results. No internal state,\r\n * no singletons, no dependency injection, no global configuration, no database\r\n * and no network (ADR-002). Side effects are limited to the directories the\r\n * caller points at (ADR-009).\r\n *\r\n * This is the ONLY public entry point. Everything under `src/` other than this\r\n * file is private and may change without notice — the `exports` map exposes a\r\n * single entry on purpose.\r\n */\r\n\r\n// ── Constants ────────────────────────────────────────────────────────────────\r\nexport {\r\n PLATFORM_PATHS,\r\n PRODUCTS_INDEX_PATH,\r\n NAME_PATTERN,\r\n VERSION_PATTERN,\r\n DEFAULT_LANGUAGES,\r\n DEFAULT_SRID,\r\n FEATURE_MODEL_TYPES,\r\n ANALYSIS_THRESHOLDS,\r\n isFeatureModelType\r\n} from './constants.js'\r\nexport type { FeatureModelType } from './constants.js'\r\n\r\n// ── Errors ───────────────────────────────────────────────────────────────────\r\nexport {\r\n LineaCoreError,\r\n InvalidArgumentError,\r\n UvlParseError,\r\n UnsupportedConversionError,\r\n FeatureSelectionInvalidError,\r\n LinePlatformNotFoundError,\r\n InvalidProductSpecError,\r\n ProductsIndexError,\r\n AnalysisRuntimeError\r\n} from './errors.js'\r\nexport type { LineaCoreErrorCode } from './errors.js'\r\n\r\n// ── Feature models ───────────────────────────────────────────────────────────\r\nexport { parseFeatureModel } from './feature-model/parse.js'\r\nexport type { FeatureModelValue } from './feature-model/parse.js'\r\nexport { convertFeatureModel } from './feature-model/convert.js'\r\nexport { detectFeatureModelType, readFeatureModel, writeFeatureModel } from './feature-model/io.js'\r\nexport type { FeatureModelLocation } from './feature-model/io.js'\r\nexport { normalizeUvl, estimateFeatureCount, emptyFeatureModelUvl } from './feature-model/text.js'\r\nexport { extractFeatureNames, computeMandatoryFeatures } from './feature-model/inspect.js'\r\nexport type { MandatoryFeaturesResult } from './feature-model/inspect.js'\r\n\r\n// ── Feature selection ────────────────────────────────────────────────────────\r\nexport {\r\n normalizeFeatureSelection,\r\n validateFeatureSelection,\r\n assertFeatureSelection,\r\n validateModelAgainstSelections\r\n} from './selection/selection.js'\r\nexport type {\r\n FeatureSelectionInput,\r\n SelectionBearingSpec,\r\n FeatureSelectionVerdict,\r\n NamedSelection,\r\n BrokenSelection,\r\n ModelAgainstSelectionsVerdict\r\n} from './selection/selection.js'\r\n\r\n// ── Product specs ────────────────────────────────────────────────────────────\r\nexport { validateProductSpec, assertProductSpec, normalizeProductSpec } from './product/spec.js'\r\nexport type {\r\n ProductSpec,\r\n ProductBasicData,\r\n ProductSpecError,\r\n ProductSpecErrorCode,\r\n ProductSpecValidation\r\n} from './product/spec.js'\r\nexport { incrementVersion } from './product/version.js'\r\nexport { buildEngineSpec } from './product/engine-spec.js'\r\nexport type { EngineSpec } from './product/engine-spec.js'\r\n\r\n// ── Products index (ADR-011) ─────────────────────────────────────────────────\r\nexport {\r\n emptyProductsIndex,\r\n parseProductsIndex,\r\n serializeProductsIndex,\r\n validateProductsIndex,\r\n addProductToIndex,\r\n renameProductInIndex,\r\n removeProductFromIndex,\r\n readProductsIndex,\r\n writeProductsIndex,\r\n reconcileProductsIndex\r\n} from './products-index/products-index.js'\r\nexport type {\r\n ProductsIndex,\r\n ProductsIndexEntry,\r\n ProductsIndexProblem,\r\n ProductsIndexProblemCode,\r\n ProductsIndexValidation,\r\n ProductsIndexReconciliation\r\n} from './products-index/products-index.js'\r\n\r\n// ── Line scaffold and platform files ─────────────────────────────────────────\r\nexport {\r\n buildLineScaffold,\r\n writeLineScaffold,\r\n DEFAULT_PLATFORM_CONFIG,\r\n DEFAULT_CODE_GITIGNORE\r\n} from './line/scaffold.js'\r\nexport type { LineScaffoldInput } from './line/scaffold.js'\r\nexport { buildExtraJs, buildTransformationJs, getPipelineFiles } from './line/platform-files.js'\r\nexport type { FileSpec, MetamodelName } from './line/platform-files.js'\r\n\r\n// ── Feature model analysis (ADR-008, ADR-021) ────────────────────────────────\r\nexport { createAnalysisRuntime, disposeAnalysisRuntime } from './analysis/runtime.js'\r\nexport type { AnalysisRuntime, AnalysisRuntimeOptions } from './analysis/runtime.js'\r\nexport {\r\n analyzeFeatureModel,\r\n analyzeFeatureModelBdd,\r\n analyzeMetric,\r\n ANALYSIS_METRICS\r\n} from './analysis/analyze.js'\r\nexport type {\r\n AnalysisMode,\r\n AnalysisMetric,\r\n FeatureModelAnalysis,\r\n FeatureModelBddAnalysis,\r\n MetricAnalysis\r\n} from './analysis/analyze.js'\r\n\r\n// ── Product derivation ───────────────────────────────────────────────────────\r\nexport { deriveProduct, deriveProductToZip } from './derivation/derive.js'\r\n\r\n// ── Archive, diff and formatting ─────────────────────────────────────────────\r\nexport { extractArchive } from './fs/archive.js'\r\nexport { diffDirectories } from './fs/diff.js'\r\nexport type { FileChange } from './fs/diff.js'\r\nexport { formatDirectory } from './fs/format.js'\r\n\r\n// ── Working directories ──────────────────────────────────────────────────────\r\nexport {\r\n resolveLinePaths,\r\n ensureDir,\r\n readTextFile,\r\n writeTextFile,\r\n fileExists\r\n} from './fs/workspace.js'\r\nexport type { LinePaths } from './fs/workspace.js'\r\n\r\n// ── Packaged assets ──────────────────────────────────────────────────────────\r\nexport { resolveAsset, assetsRoot } from './assets.js'\r\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* INTERNAL type guards. Not exported from `src/index.ts`.
|
|
3
|
+
*/
|
|
4
|
+
/** Narrows to a non-null, non-array object. */
|
|
5
|
+
export declare const isPlainObject: (value: unknown) => value is Record<string, unknown>;
|
|
6
|
+
/**
|
|
7
|
+
* Array check that preserves the declared element type.
|
|
8
|
+
*
|
|
9
|
+
* `Array.isArray(x)` widens a `readonly T[]` to `any[]` in the narrowed branch
|
|
10
|
+
* (TypeScript cannot express "readonly array" through its built-in guard), which
|
|
11
|
+
* then makes every subsequent `.name`/`.features` access an unsafe `any` member
|
|
12
|
+
* access. This guard narrows to `readonly unknown[]` instead, so intersecting it
|
|
13
|
+
* with the declared parameter type keeps `readonly T[]` intact.
|
|
14
|
+
*/
|
|
15
|
+
export declare const isArray: (value: unknown) => value is readonly unknown[];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* INTERNAL type guards. Not exported from `src/index.ts`.
|
|
3
|
+
*/
|
|
4
|
+
/** Narrows to a non-null, non-array object. */
|
|
5
|
+
export const isPlainObject = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
6
|
+
/**
|
|
7
|
+
* Array check that preserves the declared element type.
|
|
8
|
+
*
|
|
9
|
+
* `Array.isArray(x)` widens a `readonly T[]` to `any[]` in the narrowed branch
|
|
10
|
+
* (TypeScript cannot express "readonly array" through its built-in guard), which
|
|
11
|
+
* then makes every subsequent `.name`/`.features` access an unsafe `any` member
|
|
12
|
+
* access. This guard narrows to `readonly unknown[]` instead, so intersecting it
|
|
13
|
+
* with the declared parameter type keeps `readonly T[]` intact.
|
|
14
|
+
*/
|
|
15
|
+
export const isArray = (value) => Array.isArray(value);
|
|
16
|
+
//# sourceMappingURL=guards.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guards.js","sourceRoot":"","sources":["../../src/internal/guards.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,+CAA+C;AAC/C,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,KAAc,EAAoC,EAAE,CAChF,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;AAEtE;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,KAAc,EAA+B,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA","sourcesContent":["/**\r\n * INTERNAL type guards. Not exported from `src/index.ts`.\r\n */\r\n\r\n/** Narrows to a non-null, non-array object. */\r\nexport const isPlainObject = (value: unknown): value is Record<string, unknown> =>\r\n typeof value === 'object' && value !== null && !Array.isArray(value)\r\n\r\n/**\r\n * Array check that preserves the declared element type.\r\n *\r\n * `Array.isArray(x)` widens a `readonly T[]` to `any[]` in the narrowed branch\r\n * (TypeScript cannot express \"readonly array\" through its built-in guard), which\r\n * then makes every subsequent `.name`/`.features` access an unsafe `any` member\r\n * access. This guard narrows to `readonly unknown[]` instead, so intersecting it\r\n * with the declared parameter type keeps `readonly T[]` intact.\r\n */\r\nexport const isArray = (value: unknown): value is readonly unknown[] => Array.isArray(value)\r\n"]}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A file to be written somewhere, described without deciding where.
|
|
3
|
+
*
|
|
4
|
+
* The pure half of the scaffold API returns these so linea-server can push them
|
|
5
|
+
* to GitLab and linea-cli can write them to disk, from the same description.
|
|
6
|
+
*/
|
|
7
|
+
export interface FileSpec {
|
|
8
|
+
/** Repository-relative path, always POSIX (`/`), never absolute. */
|
|
9
|
+
readonly path: string;
|
|
10
|
+
/** File contents. */
|
|
11
|
+
readonly content: string;
|
|
12
|
+
/** How `content` is encoded. Every seeded file is text today. */
|
|
13
|
+
readonly encoding: 'text' | 'base64';
|
|
14
|
+
}
|
|
15
|
+
/** Metamodels that contribute extra template fragments. */
|
|
16
|
+
declare const METAMODEL_TEMPLATES: {
|
|
17
|
+
readonly UML: {
|
|
18
|
+
readonly extra: "metamodels/dataModel/extra.js";
|
|
19
|
+
readonly transformation: "metamodels/dataModel/transformation.js";
|
|
20
|
+
};
|
|
21
|
+
readonly SENSOR: {
|
|
22
|
+
readonly extra: "metamodels/sensor/extra.js";
|
|
23
|
+
readonly transformation: "metamodels/sensor/transformation.js";
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
/** A metamodel name recognised by the template factory. */
|
|
27
|
+
export type MetamodelName = keyof typeof METAMODEL_TEMPLATES;
|
|
28
|
+
/**
|
|
29
|
+
* Builds `src/platform/extra.js` for a line.
|
|
30
|
+
*
|
|
31
|
+
* WRITING YOUR OWN `extra.js`: do NOT use `//` line comments. The template
|
|
32
|
+
* processor concatenates this file into the function it builds and then strips
|
|
33
|
+
* every newline from it (`spl-js-engine/src/template-engine/processor.js:28`),
|
|
34
|
+
* so a line comment swallows the rest of that function — including its final
|
|
35
|
+
* `return`. Every annotated file then processes to nothing and, because the
|
|
36
|
+
* engine skips empty output, the derivation produces ZERO files WITHOUT raising
|
|
37
|
+
* an error. Use `/* ... *\/` blocks. Neither the monolith's `core/extra.js` nor
|
|
38
|
+
* its mock LPS uses line comments, for exactly this reason.
|
|
39
|
+
*
|
|
40
|
+
* @param params.models Metamodels chosen for the line, e.g. `['UML']`. Unknown
|
|
41
|
+
* names are ignored, matching the monolith.
|
|
42
|
+
* @returns The file contents: core template plus one fragment per known model.
|
|
43
|
+
* @throws {InvalidArgumentError} when `models` is not an array of strings.
|
|
44
|
+
*/
|
|
45
|
+
export declare const buildExtraJs: ({ models }: {
|
|
46
|
+
models?: readonly string[];
|
|
47
|
+
}) => string;
|
|
48
|
+
/**
|
|
49
|
+
* Builds `src/platform/transformation.js` for a line.
|
|
50
|
+
*
|
|
51
|
+
* WRITING YOUR OWN `transformation.js`: the same `//` trap described on
|
|
52
|
+
* {@link buildExtraJs} applies here — the processor strips every newline, so a
|
|
53
|
+
* line comment silently swallows the rest of the generated function and the
|
|
54
|
+
* derivation produces ZERO files without raising. Use block comments.
|
|
55
|
+
*
|
|
56
|
+
* @param params.models Metamodels chosen for the line. Unknown names are ignored.
|
|
57
|
+
* @returns The file contents: core template plus one fragment per known model.
|
|
58
|
+
* @throws {InvalidArgumentError} when `models` is not an array of strings.
|
|
59
|
+
*/
|
|
60
|
+
export declare const buildTransformationJs: ({ models }: {
|
|
61
|
+
models?: readonly string[];
|
|
62
|
+
}) => string;
|
|
63
|
+
/**
|
|
64
|
+
* The default CI pipeline files seeded into every new line repository.
|
|
65
|
+
*
|
|
66
|
+
* Migrated from `PipelineFileFactory.js:PIPELINE_FILES`, same paths and same
|
|
67
|
+
* order. A function rather than an exported constant so no module-level state
|
|
68
|
+
* holds the file contents (ADR-014) and so each caller gets its own array.
|
|
69
|
+
*
|
|
70
|
+
* @returns The pipeline files, in the order the monolith creates them.
|
|
71
|
+
*/
|
|
72
|
+
export declare const getPipelineFiles: () => FileSpec[];
|
|
73
|
+
export {};
|