nesoi 3.0.12 → 3.0.14
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/lib/compiler/apps/monolyth/stages/2_build_typescript_stage.js +5 -2
- package/lib/compiler/apps/monolyth/stages/3_copy_types_stage.js +2 -2
- package/lib/compiler/apps/monolyth/stages/4_dump_modules_stage.js +2 -2
- package/lib/compiler/apps/monolyth/stages/7_dump_package_json_stage.js +4 -1
- package/lib/compiler/compiler.d.ts +2 -0
- package/lib/compiler/compiler.js +10 -38
- package/lib/compiler/elements/cached.element.d.ts +11 -0
- package/lib/compiler/elements/cached.element.js +18 -0
- package/lib/compiler/elements/element.d.ts +3 -1
- package/lib/compiler/elements/element.js +3 -1
- package/lib/compiler/elements/externals.element.d.ts +1 -1
- package/lib/compiler/elements/externals.element.js +2 -35
- package/lib/compiler/module.d.ts +3 -2
- package/lib/compiler/module.js +9 -2
- package/lib/compiler/progressive.d.ts +71 -0
- package/lib/compiler/progressive.js +164 -0
- package/lib/compiler/stages/1_scan_stage.js +5 -2
- package/lib/compiler/stages/2_treeshake_stage.js +7 -1
- package/lib/compiler/stages/3_extract_ts_stage.js +9 -0
- package/lib/compiler/stages/4_build_schemas_stage.js +10 -1
- package/lib/compiler/stages/5_inject_ts_stage.js +3 -0
- package/lib/compiler/stages/6_build_elements_stage.js +3 -0
- package/lib/compiler/stages/7_dump_stage.d.ts +4 -1
- package/lib/compiler/stages/7_dump_stage.js +108 -44
- package/lib/compiler/stages/8_diagnose_stage.js +3 -0
- package/lib/compiler/treeshake.d.ts +5 -2
- package/lib/compiler/treeshake.js +41 -8
- package/lib/compiler/typescript/bridge/inject.js +2 -0
- package/lib/compiler/typescript/transformers/app_inject.transformer.js +1 -1
- package/lib/elements/blocks/resource/resource.js +1 -1
- package/lib/elements/entities/bucket/bucket.d.ts +3 -1
- package/lib/elements/entities/bucket/bucket.js +18 -6
- package/lib/engine/apps/app.config.d.ts +11 -9
- package/lib/engine/apps/app.config.js +1 -2
- package/lib/engine/apps/app.js +2 -2
- package/lib/engine/data/trash.d.ts +13 -10
- package/lib/engine/data/trash.js +33 -0
- package/lib/engine/dependency.d.ts +6 -0
- package/lib/engine/dependency.js +1 -0
- package/lib/engine/module.d.ts +4 -2
- package/lib/engine/module.js +8 -3
- package/lib/engine/space.d.ts +1 -1
- package/lib/engine/space.js +14 -5
- package/lib/engine/transaction/nodes/bucket.trx_node.d.ts +5 -1
- package/lib/engine/transaction/nodes/bucket.trx_node.js +9 -2
- package/lib/engine/transaction/nodes/bucket_query.trx_node.d.ts +3 -3
- package/lib/engine/transaction/nodes/bucket_query.trx_node.js +2 -2
- package/lib/engine/transaction/trx_engine.d.ts +1 -1
- package/lib/engine/transaction/trx_node.d.ts +1 -1
- package/lib/engine/transaction/trx_node.js +3 -1
- package/lib/engine/tree.d.ts +8 -1
- package/lib/engine/tree.js +45 -25
- package/lib/engine/util/hash.d.ts +2 -1
- package/lib/engine/util/hash.js +10 -1
- package/package.json +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
|
@@ -62,8 +62,11 @@ class BuildTypescriptStage {
|
|
|
62
62
|
return space_1.Space.path(compiler.space, path);
|
|
63
63
|
});
|
|
64
64
|
const info = app_1.App.getInfo(this.app);
|
|
65
|
-
const modulePaths =
|
|
66
|
-
|
|
65
|
+
const modulePaths = [];
|
|
66
|
+
space_1.Space.scan(compiler.space, (name) => {
|
|
67
|
+
if (info.spaceModules.includes(name)) {
|
|
68
|
+
modulePaths.push(space_1.Space.path(compiler.space, '.nesoi', name));
|
|
69
|
+
}
|
|
67
70
|
});
|
|
68
71
|
const space = compiler.space;
|
|
69
72
|
const spacePath = space_1.Space.path(space);
|
|
@@ -57,8 +57,8 @@ class CopyTypesStage {
|
|
|
57
57
|
const { compiler, dirs } = this.monolyth;
|
|
58
58
|
const info = app_1.App.getInfo(this.app);
|
|
59
59
|
// Copy module types to types folder
|
|
60
|
-
for (const
|
|
61
|
-
const module = compiler.modules[
|
|
60
|
+
for (const name of info.spaceModules) {
|
|
61
|
+
const module = compiler.modules[name];
|
|
62
62
|
const from = space_1.Space.path(compiler.space, '.nesoi', module.lowName + '.module.ts');
|
|
63
63
|
const to = path.resolve(dirs.build_types, module.lowName + '.module.ts');
|
|
64
64
|
log_1.Log.debug('compiler', 'monolyth', `Copying module types from ${from} to ${to}`);
|
|
@@ -54,8 +54,8 @@ class DumpModulesStage {
|
|
|
54
54
|
log_1.Log.info('compiler', 'monolyth', 'Dumping modules to build/modules folder...');
|
|
55
55
|
const { compiler, dirs } = this.monolyth;
|
|
56
56
|
const info = app_1.App.getInfo(this.app);
|
|
57
|
-
for (const
|
|
58
|
-
const module = compiler.modules[
|
|
57
|
+
for (const name of info.spaceModules) {
|
|
58
|
+
const module = compiler.modules[name];
|
|
59
59
|
this.dumpModule(module, dirs.build_modules);
|
|
60
60
|
}
|
|
61
61
|
}
|
|
@@ -54,7 +54,10 @@ class DumpPackageJsonStage {
|
|
|
54
54
|
async run() {
|
|
55
55
|
log_1.Log.info('compiler', 'monolyth', 'Dumping package.json to build folder...');
|
|
56
56
|
const { config, compiler, dirs } = this.monolyth;
|
|
57
|
-
const
|
|
57
|
+
const packageJsonPath = config.nesoiPath
|
|
58
|
+
? path.join(config.nesoiPath, 'package.json')
|
|
59
|
+
: path.join('..', '..', '..', '..', '..', 'package.json');
|
|
60
|
+
const nesoiPackageJson = await Promise.resolve(`${packageJsonPath}`).then(s => __importStar(require(s)));
|
|
58
61
|
const spacePackageJson = await Promise.resolve(`${space_1.Space.path(compiler.space, 'package.json')}`).then(s => __importStar(require(s)));
|
|
59
62
|
const filePath = path.resolve(dirs.build, 'package.json');
|
|
60
63
|
const scripts = {
|
package/lib/compiler/compiler.js
CHANGED
|
@@ -1,43 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
4
|
};
|
|
38
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
6
|
exports.Compiler = void 0;
|
|
40
|
-
const fs = __importStar(require("fs"));
|
|
41
7
|
const tree_1 = require("../engine/tree");
|
|
42
8
|
const space_1 = require("../engine/space");
|
|
43
9
|
const typescript_compiler_1 = require("./typescript/typescript_compiler");
|
|
@@ -51,18 +17,22 @@ const _7_dump_stage_1 = require("./stages/7_dump_stage");
|
|
|
51
17
|
const console_1 = __importDefault(require("../engine/util/console"));
|
|
52
18
|
const log_1 = require("../engine/util/log");
|
|
53
19
|
const _8_diagnose_stage_1 = require("./stages/8_diagnose_stage");
|
|
20
|
+
const fs_1 = __importDefault(require("fs"));
|
|
54
21
|
class Compiler {
|
|
55
22
|
constructor(space, config) {
|
|
56
23
|
this.space = space;
|
|
57
24
|
this.config = config;
|
|
58
25
|
this.modules = {};
|
|
59
26
|
this.tree = new tree_1.ModuleTree({}, this.config);
|
|
27
|
+
console_1.default.header('Elements Compiler');
|
|
28
|
+
log_1.Log.info('compiler', 'ts', 'Loading TypeScript...');
|
|
60
29
|
this.tsCompiler = new typescript_compiler_1.TypeScriptCompiler(space, config?.nesoiPath);
|
|
61
30
|
}
|
|
62
31
|
async run() {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
32
|
+
if (this.config?.reset) {
|
|
33
|
+
// Cleanup .nesoi folder
|
|
34
|
+
fs_1.default.rmSync(space_1.Space.path(this.space, '.nesoi'), { recursive: true, force: true });
|
|
35
|
+
}
|
|
66
36
|
try {
|
|
67
37
|
await new _1_scan_stage_1.ScanStage(this).run();
|
|
68
38
|
await new _2_treeshake_stage_1.TreeshakeStage(this).run();
|
|
@@ -71,7 +41,9 @@ class Compiler {
|
|
|
71
41
|
await new _5_inject_ts_stage_1.InjectTSStage(this).run();
|
|
72
42
|
await new _6_build_elements_stage_1.BuildElementsStage(this).run();
|
|
73
43
|
await new _7_dump_stage_1.DumpStage(this).run();
|
|
74
|
-
|
|
44
|
+
if (this.config?.diagnose) {
|
|
45
|
+
await new _8_diagnose_stage_1.DiagnoseStage(this).run();
|
|
46
|
+
}
|
|
75
47
|
}
|
|
76
48
|
catch (e) {
|
|
77
49
|
log_1.Log.error('compiler', 'nesoi', e.toString(), { stack: e.stack });
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ResolvedBuilderNode } from "../../engine/dependency";
|
|
2
|
+
import { Compiler } from '../compiler';
|
|
3
|
+
import { Element } from './element';
|
|
4
|
+
import { AnyElementSchema } from "../../engine/module";
|
|
5
|
+
import { ProgressiveBuildCache } from '../progressive';
|
|
6
|
+
export declare class CachedElement extends Element<AnyElementSchema> {
|
|
7
|
+
constructor(compiler: Compiler, node: ResolvedBuilderNode);
|
|
8
|
+
protected prepare(): void;
|
|
9
|
+
protected buildType(): string;
|
|
10
|
+
dumpTypeSchema(cache: ProgressiveBuildCache): string;
|
|
11
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CachedElement = void 0;
|
|
4
|
+
const element_1 = require("./element");
|
|
5
|
+
class CachedElement extends element_1.Element {
|
|
6
|
+
constructor(compiler, node) {
|
|
7
|
+
super(compiler, node.module, node.type, [node.filepath], node.progressive.schema, [], undefined, {});
|
|
8
|
+
}
|
|
9
|
+
prepare() {
|
|
10
|
+
}
|
|
11
|
+
buildType() {
|
|
12
|
+
return '';
|
|
13
|
+
}
|
|
14
|
+
dumpTypeSchema(cache) {
|
|
15
|
+
return cache.types.elements[this.tag];
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.CachedElement = CachedElement;
|
|
@@ -5,6 +5,7 @@ import { $Job } from "../../elements/blocks/job/job.schema";
|
|
|
5
5
|
import { $Queue } from "../../elements/blocks/queue/queue.schema";
|
|
6
6
|
import { Compiler } from '../compiler';
|
|
7
7
|
import { $Block } from "../../elements/blocks/block.schema";
|
|
8
|
+
import { ProgressiveBuildCache } from '../progressive';
|
|
8
9
|
export type TypeAsObj = string | ({
|
|
9
10
|
[x: string]: TypeAsObj;
|
|
10
11
|
} & {
|
|
@@ -25,6 +26,7 @@ export declare abstract class Element<T extends AnyElementSchema> {
|
|
|
25
26
|
static Any: any;
|
|
26
27
|
static Never: any;
|
|
27
28
|
type: TypeAsObj;
|
|
29
|
+
tag: string;
|
|
28
30
|
lowName: string;
|
|
29
31
|
highName: string;
|
|
30
32
|
typeName: string;
|
|
@@ -35,7 +37,7 @@ export declare abstract class Element<T extends AnyElementSchema> {
|
|
|
35
37
|
private bridgeImports;
|
|
36
38
|
protected customImports(nesoiPath: string): string;
|
|
37
39
|
dumpFileSchema(nesoiPath: string): string;
|
|
38
|
-
dumpTypeSchema(): string;
|
|
40
|
+
dumpTypeSchema(cache?: ProgressiveBuildCache): string;
|
|
39
41
|
static makeAuthnType(authn: string[]): ({
|
|
40
42
|
[x: string]: TypeAsObj;
|
|
41
43
|
} & {
|
|
@@ -14,6 +14,7 @@ class Element {
|
|
|
14
14
|
this.inlineRoot = inlineRoot;
|
|
15
15
|
this.bridge = bridge;
|
|
16
16
|
const names = name_helpers_1.NameHelpers.names(schema);
|
|
17
|
+
this.tag = `${module}::${$t}:${names.low}`;
|
|
17
18
|
this.lowName = names.low;
|
|
18
19
|
this.highName = names.high;
|
|
19
20
|
this.typeName = names.type;
|
|
@@ -43,7 +44,8 @@ class Element {
|
|
|
43
44
|
+ `const ${this.typeName}: ${this.typeName} = ${dump_helpers_1.DumpHelpers.dumpSchema(this.schema)}\n`
|
|
44
45
|
+ `export default ${this.typeName}`;
|
|
45
46
|
}
|
|
46
|
-
|
|
47
|
+
// Cache is only used on CachedElement
|
|
48
|
+
dumpTypeSchema(cache) {
|
|
47
49
|
this.type = this.buildType();
|
|
48
50
|
const typeschema = {
|
|
49
51
|
'constants': '$Constants',
|
|
@@ -15,5 +15,5 @@ export declare class ExternalsElement extends Element<$Externals> {
|
|
|
15
15
|
constructor(compiler: Compiler, module: string, $t: string, files: string[], schema: $Externals, dependencies: ResolvedBuilderNode[], inlineRoot?: ResolvedBuilderNode | undefined, bridge?: ResolvedBuilderNode['bridge']);
|
|
16
16
|
protected buildType(): {};
|
|
17
17
|
dumpFileSchema(): string;
|
|
18
|
-
|
|
18
|
+
getModuleDependencies(): string[];
|
|
19
19
|
}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ExternalsElement = void 0;
|
|
4
4
|
const element_1 = require("./element");
|
|
5
|
-
const name_helpers_1 = require("../helpers/name_helpers");
|
|
6
5
|
const dump_helpers_1 = require("../helpers/dump_helpers");
|
|
7
6
|
class ExternalsElement extends element_1.Element {
|
|
8
7
|
constructor(compiler, module, $t, files, schema, dependencies, inlineRoot, bridge) {
|
|
@@ -19,45 +18,15 @@ class ExternalsElement extends element_1.Element {
|
|
|
19
18
|
bucket: {},
|
|
20
19
|
job: {}
|
|
21
20
|
};
|
|
22
|
-
// Object.entries(schema.buckets).forEach(([key, ref]) => {
|
|
23
|
-
// const element = compiler.modules[ref.module].elements
|
|
24
|
-
// .find(el => el.lowName === ref.name && el.$t === 'bucket')
|
|
25
|
-
// if (!element) {
|
|
26
|
-
// throw new Error(`External bucket ${ref.name} not found`)
|
|
27
|
-
// }
|
|
28
|
-
// this.elements.bucket[key] = element as BucketElement;
|
|
29
|
-
// })
|
|
30
|
-
// Object.entries(schema.jobs).forEach(([key, ref]) => {
|
|
31
|
-
// const element = compiler.modules[ref.module].elements
|
|
32
|
-
// .find(el => el.lowName === ref.name && el.$t === 'job')
|
|
33
|
-
// if (!element) {
|
|
34
|
-
// throw new Error(`External job ${ref.name} not found`)
|
|
35
|
-
// }
|
|
36
|
-
// this.elements.job[key] = element as JobElement;
|
|
37
|
-
// })
|
|
38
|
-
// this.type = this.buildType();
|
|
39
21
|
}
|
|
40
22
|
buildType() {
|
|
41
23
|
return {};
|
|
42
|
-
// if (!this.elements) {
|
|
43
|
-
// return {};
|
|
44
|
-
// }
|
|
45
|
-
// const type = {
|
|
46
|
-
// models: {},
|
|
47
|
-
// buckets: {},
|
|
48
|
-
// jobs: {}
|
|
49
|
-
// } as ObjTypeAsObj;
|
|
50
|
-
// Object.entries(this.elements.bucket).map(([tag, el]) => {
|
|
51
|
-
// type.models[tag] = (el.type as ObjTypeAsObj).model;
|
|
52
|
-
// type.buckets[tag] = (el.type as ObjTypeAsObj).bucket;
|
|
53
|
-
// })
|
|
54
|
-
// return type;
|
|
55
24
|
}
|
|
56
25
|
dumpFileSchema() {
|
|
57
26
|
return `const ${this.typeName} = ${dump_helpers_1.DumpHelpers.dumpSchema(this.schema)}\n`
|
|
58
27
|
+ `export default ${this.typeName}`;
|
|
59
28
|
}
|
|
60
|
-
|
|
29
|
+
getModuleDependencies() {
|
|
61
30
|
this.type = this.buildType();
|
|
62
31
|
this.prepare();
|
|
63
32
|
const externalModules = new Set();
|
|
@@ -75,9 +44,7 @@ class ExternalsElement extends element_1.Element {
|
|
|
75
44
|
}
|
|
76
45
|
});
|
|
77
46
|
});
|
|
78
|
-
return Array.from(externalModules)
|
|
79
|
-
.map(module => `import ${name_helpers_1.NameHelpers.nameLowToHigh(module)}Module from './${module}.module'`)
|
|
80
|
-
.join('\n');
|
|
47
|
+
return Array.from(externalModules);
|
|
81
48
|
}
|
|
82
49
|
}
|
|
83
50
|
exports.ExternalsElement = ExternalsElement;
|
package/lib/compiler/module.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ import { ResolvedBuilderNode } from "../engine/dependency";
|
|
|
12
12
|
import { $Module } from "../schema";
|
|
13
13
|
import { QueueElement } from './elements/queue.element';
|
|
14
14
|
import { Element } from './elements/element';
|
|
15
|
+
import { CachedElement } from './elements/cached.element';
|
|
15
16
|
export declare class CompilerModule {
|
|
16
17
|
compiler: Compiler;
|
|
17
18
|
lowName: string;
|
|
@@ -19,6 +20,6 @@ export declare class CompilerModule {
|
|
|
19
20
|
typeName: string;
|
|
20
21
|
module: Module<any, $Module>;
|
|
21
22
|
elements: Element<any>[];
|
|
22
|
-
constructor(compiler: Compiler, name: string, path: string);
|
|
23
|
-
buildElementNode(node: ResolvedBuilderNode): Promise<MessageElement | BucketElement | JobElement | ResourceElement | MachineElement | ControllerElement | ConstantsElement | ExternalsElement | QueueElement | undefined>;
|
|
23
|
+
constructor(compiler: Compiler, name: string, path: string, subdir?: string[]);
|
|
24
|
+
buildElementNode(node: ResolvedBuilderNode): Promise<MessageElement | BucketElement | JobElement | ResourceElement | MachineElement | ControllerElement | ConstantsElement | ExternalsElement | QueueElement | CachedElement | undefined>;
|
|
24
25
|
}
|
package/lib/compiler/module.js
CHANGED
|
@@ -48,8 +48,9 @@ const constants_element_1 = require("./elements/constants.element");
|
|
|
48
48
|
const externals_element_1 = require("./elements/externals.element");
|
|
49
49
|
const log_1 = require("../engine/util/log");
|
|
50
50
|
const queue_element_1 = require("./elements/queue.element");
|
|
51
|
+
const cached_element_1 = require("./elements/cached.element");
|
|
51
52
|
class CompilerModule {
|
|
52
|
-
constructor(compiler, name, path) {
|
|
53
|
+
constructor(compiler, name, path, subdir = []) {
|
|
53
54
|
this.compiler = compiler;
|
|
54
55
|
this.elements = [];
|
|
55
56
|
this.lowName = name;
|
|
@@ -58,10 +59,16 @@ class CompilerModule {
|
|
|
58
59
|
if (path && !fs.existsSync(path)) {
|
|
59
60
|
throw error_1.CompilerError.DirectoryDoesntExists(path);
|
|
60
61
|
}
|
|
61
|
-
this.module = new module_1.Module(name, { dirpath: path });
|
|
62
|
+
this.module = new module_1.Module(name, { dirpath: path }, subdir);
|
|
62
63
|
}
|
|
63
64
|
async buildElementNode(node) {
|
|
64
65
|
log_1.Log.trace('compiler', 'module', `${this.lowName}::${(0, log_1.scopeTag)(node.type, node.name)} Compiling${node.isInline ? ' (inline)' : ''}`);
|
|
66
|
+
// Progressive (Cached)
|
|
67
|
+
if (node.progressive) {
|
|
68
|
+
const el = new cached_element_1.CachedElement(this.compiler, node);
|
|
69
|
+
this.elements.push(el);
|
|
70
|
+
return el;
|
|
71
|
+
}
|
|
65
72
|
// Entities
|
|
66
73
|
if (node.type === 'constants') {
|
|
67
74
|
const el = new constants_element_1.ConstantsElement(this.compiler, this.lowName, 'constants', node.filepath, node.schema, node.dependencies.map(dep => dep.node), undefined, node.bridge);
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { BuilderNode } from "../engine/dependency";
|
|
2
|
+
import { AnySpace } from "../engine/space";
|
|
3
|
+
import { BuilderType } from "../schema";
|
|
4
|
+
import { Compiler } from './compiler';
|
|
5
|
+
import { ObjTypeAsObj } from './elements/element';
|
|
6
|
+
export type ProgressiveBuildCache = {
|
|
7
|
+
nesoidir: string;
|
|
8
|
+
hash: {
|
|
9
|
+
$: string;
|
|
10
|
+
space: string;
|
|
11
|
+
modules: {
|
|
12
|
+
[name: string]: {
|
|
13
|
+
$: string;
|
|
14
|
+
nodes: {
|
|
15
|
+
[tag: string]: string;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
files: {
|
|
20
|
+
[filepath: string]: string;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
files: {
|
|
24
|
+
[filepath: string]: {
|
|
25
|
+
type: BuilderType[];
|
|
26
|
+
elements: string[];
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
modules: {
|
|
30
|
+
[name: string]: {
|
|
31
|
+
dependencies: {
|
|
32
|
+
modules: string[];
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
types: {
|
|
37
|
+
space: ObjTypeAsObj;
|
|
38
|
+
modules: {
|
|
39
|
+
[name: string]: ObjTypeAsObj;
|
|
40
|
+
};
|
|
41
|
+
elements: {
|
|
42
|
+
[tag: string]: string;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
export declare class ProgressiveBuild {
|
|
47
|
+
static cache(compiler: Compiler, $?: {
|
|
48
|
+
init: boolean;
|
|
49
|
+
}): ProgressiveBuildCache | Promise<ProgressiveBuildCache>;
|
|
50
|
+
static treeshake(cache: ProgressiveBuildCache, filepath: string): Promise<BuilderNode[] | undefined>;
|
|
51
|
+
static empty(): ProgressiveBuildCache;
|
|
52
|
+
static init(compiler: Compiler): Promise<ProgressiveBuildCache>;
|
|
53
|
+
static save(space: AnySpace, cache: ProgressiveBuildCache, hash?: ProgressiveBuildCache['hash']): Promise<void>;
|
|
54
|
+
static hash(compiler: Compiler): Promise<{
|
|
55
|
+
$: string;
|
|
56
|
+
space: string;
|
|
57
|
+
modules: {
|
|
58
|
+
[name: string]: {
|
|
59
|
+
$: string;
|
|
60
|
+
nodes: {
|
|
61
|
+
[tag: string]: string;
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
files: {
|
|
66
|
+
[filepath: string]: string;
|
|
67
|
+
};
|
|
68
|
+
}>;
|
|
69
|
+
private static nodes;
|
|
70
|
+
private static schemas;
|
|
71
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.ProgressiveBuild = void 0;
|
|
40
|
+
const fs_1 = __importStar(require("fs"));
|
|
41
|
+
const dependency_1 = require("../engine/dependency");
|
|
42
|
+
const space_1 = require("../engine/space");
|
|
43
|
+
const hash_1 = require("../engine/util/hash");
|
|
44
|
+
const path_1 = __importDefault(require("path"));
|
|
45
|
+
class ProgressiveBuild {
|
|
46
|
+
static cache(compiler, $) {
|
|
47
|
+
const path = space_1.Space.path(compiler.space, '.nesoi', '.cache');
|
|
48
|
+
if (!(0, fs_1.existsSync)(path)) {
|
|
49
|
+
return this.init(compiler);
|
|
50
|
+
}
|
|
51
|
+
const file = fs_1.default.readFileSync(path);
|
|
52
|
+
return JSON.parse(file.toString());
|
|
53
|
+
}
|
|
54
|
+
static async treeshake(cache, filepath) {
|
|
55
|
+
const file = cache.files[filepath];
|
|
56
|
+
// Currently, progressive build of constants and externals is
|
|
57
|
+
// not supported, given that the schemas are merged, so checking
|
|
58
|
+
// the hash of a single file is not enough to ensure changes
|
|
59
|
+
if (!file.type.includes('constants') && !file.type.includes('externals')) {
|
|
60
|
+
const hash = await hash_1.Hash.file(filepath);
|
|
61
|
+
if (hash === cache.hash.files[filepath]) {
|
|
62
|
+
return ProgressiveBuild.nodes(cache, filepath);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
static empty() {
|
|
67
|
+
const cache = {
|
|
68
|
+
nesoidir: '',
|
|
69
|
+
hash: {
|
|
70
|
+
$: '',
|
|
71
|
+
files: {},
|
|
72
|
+
modules: {},
|
|
73
|
+
space: ''
|
|
74
|
+
},
|
|
75
|
+
files: {},
|
|
76
|
+
modules: {},
|
|
77
|
+
types: {
|
|
78
|
+
space: {},
|
|
79
|
+
modules: {},
|
|
80
|
+
elements: {}
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
return cache;
|
|
84
|
+
}
|
|
85
|
+
static async init(compiler) {
|
|
86
|
+
const cache = {
|
|
87
|
+
nesoidir: space_1.Space.path(compiler.space, '.nesoi'),
|
|
88
|
+
hash: await ProgressiveBuild.hash(compiler),
|
|
89
|
+
files: {},
|
|
90
|
+
modules: {},
|
|
91
|
+
types: {
|
|
92
|
+
space: {},
|
|
93
|
+
modules: {},
|
|
94
|
+
elements: {}
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
return cache;
|
|
98
|
+
}
|
|
99
|
+
static async save(space, cache, hash) {
|
|
100
|
+
if (!fs_1.default.existsSync(cache.nesoidir)) {
|
|
101
|
+
fs_1.default.mkdirSync(cache.nesoidir, { recursive: true });
|
|
102
|
+
}
|
|
103
|
+
cache.hash = hash || cache.hash;
|
|
104
|
+
const cachePath = path_1.default.join(cache.nesoidir, '.cache');
|
|
105
|
+
const str = JSON.stringify(cache);
|
|
106
|
+
fs_1.default.writeFileSync(cachePath, str);
|
|
107
|
+
}
|
|
108
|
+
static async hash(compiler) {
|
|
109
|
+
const out = {
|
|
110
|
+
$: '',
|
|
111
|
+
files: {},
|
|
112
|
+
space: await hash_1.Hash.file(space_1.Space.path(compiler.space, 'nesoi.ts')),
|
|
113
|
+
modules: {}
|
|
114
|
+
};
|
|
115
|
+
// Calculate a hash for each module
|
|
116
|
+
const modules = compiler.tree.allNodesByModule();
|
|
117
|
+
for (const name in modules) {
|
|
118
|
+
out.modules[name] = {
|
|
119
|
+
$: '',
|
|
120
|
+
nodes: {}
|
|
121
|
+
};
|
|
122
|
+
const module = modules[name];
|
|
123
|
+
for (const node of module) {
|
|
124
|
+
if (Array.isArray(node.filepath)) {
|
|
125
|
+
// Currently, progressive build of constants and externals is
|
|
126
|
+
// not supported, so these are ignore.
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
const hash = await hash_1.Hash.file(node.filepath);
|
|
130
|
+
out.files[node.filepath] = hash;
|
|
131
|
+
out.modules[name].nodes[node.tag] = hash;
|
|
132
|
+
}
|
|
133
|
+
out.modules[name].$ = hash_1.Hash.merge(out.modules[name].nodes);
|
|
134
|
+
}
|
|
135
|
+
out.$ = hash_1.Hash.merge({
|
|
136
|
+
__space: out.space,
|
|
137
|
+
...out.modules
|
|
138
|
+
});
|
|
139
|
+
return out;
|
|
140
|
+
}
|
|
141
|
+
// treeshake
|
|
142
|
+
static async nodes(cache, filepath) {
|
|
143
|
+
const file = cache.files[filepath];
|
|
144
|
+
const schemas = await this.schemas(cache, file);
|
|
145
|
+
return schemas.map(schema => new dependency_1.BuilderNode({
|
|
146
|
+
module: schema.module,
|
|
147
|
+
type: schema.$t,
|
|
148
|
+
name: schema.name,
|
|
149
|
+
filepath,
|
|
150
|
+
dependencies: [],
|
|
151
|
+
builder: undefined,
|
|
152
|
+
progressive: { schema }
|
|
153
|
+
}));
|
|
154
|
+
}
|
|
155
|
+
static async schemas(cache, file) {
|
|
156
|
+
const schemas = [];
|
|
157
|
+
for (const schemaPath of file.elements) {
|
|
158
|
+
const schema = (await Promise.resolve(`${schemaPath}`).then(s => __importStar(require(s)))).default;
|
|
159
|
+
schemas.push(schema);
|
|
160
|
+
}
|
|
161
|
+
return schemas;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
exports.ProgressiveBuild = ProgressiveBuild;
|
|
@@ -16,10 +16,13 @@ class ScanStage {
|
|
|
16
16
|
this.compiler = compiler;
|
|
17
17
|
}
|
|
18
18
|
async run() {
|
|
19
|
+
const t0 = new Date().getTime();
|
|
19
20
|
log_1.Log.info('compiler', 'stage.scan', 'Scanning module folders...');
|
|
20
|
-
space_1.Space.scan(this.compiler.space, (name, path) => {
|
|
21
|
-
this.compiler.modules[name] = new module_1.CompilerModule(this.compiler, name, path);
|
|
21
|
+
space_1.Space.scan(this.compiler.space, (name, path, subdir) => {
|
|
22
|
+
this.compiler.modules[name] = new module_1.CompilerModule(this.compiler, name, path, subdir);
|
|
22
23
|
});
|
|
24
|
+
const t = new Date().getTime();
|
|
25
|
+
log_1.Log.debug('compiler', 'stage.scan', `[t: ${(t - t0) / 1000} ms]`);
|
|
23
26
|
log_1.Log.debug('compiler', 'stage.scan', `Modules (${Object.keys(this.compiler.modules).length}): ${Object.keys(this.compiler.modules)}`);
|
|
24
27
|
}
|
|
25
28
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TreeshakeStage = void 0;
|
|
4
4
|
const log_1 = require("../../engine/util/log");
|
|
5
|
+
const progressive_1 = require("../progressive");
|
|
5
6
|
/**
|
|
6
7
|
* [Compiler Stage #2]
|
|
7
8
|
* Treeshake each module to finds it's nodes, inline nodes and dependencies,
|
|
@@ -16,12 +17,17 @@ class TreeshakeStage {
|
|
|
16
17
|
}
|
|
17
18
|
async run() {
|
|
18
19
|
log_1.Log.info('compiler', 'stage.treeshake', 'Treeshaking Nodes and Resolving Dependencies...');
|
|
20
|
+
const t0 = new Date().getTime();
|
|
19
21
|
const modules = {};
|
|
20
22
|
Object.entries(this.compiler.modules).forEach(([name, module]) => {
|
|
21
23
|
modules[name] = module.module;
|
|
22
24
|
});
|
|
23
25
|
this.compiler.tree.modules = modules;
|
|
24
|
-
await this.compiler
|
|
26
|
+
const cache = await progressive_1.ProgressiveBuild.cache(this.compiler);
|
|
27
|
+
await this.compiler.tree.resolve(cache);
|
|
28
|
+
await progressive_1.ProgressiveBuild.save(this.compiler.space, cache);
|
|
29
|
+
const t = new Date().getTime();
|
|
30
|
+
log_1.Log.debug('compiler', 'stage.treeshake', `[t: ${(t - t0) / 1000} ms]`);
|
|
25
31
|
}
|
|
26
32
|
}
|
|
27
33
|
exports.TreeshakeStage = TreeshakeStage;
|
|
@@ -17,6 +17,7 @@ class ExtractTSStage {
|
|
|
17
17
|
}
|
|
18
18
|
run() {
|
|
19
19
|
log_1.Log.info('compiler', 'stage.extract_ts', 'Extracting TypeScript code from builders...');
|
|
20
|
+
const t0 = new Date().getTime();
|
|
20
21
|
const { tree } = this.compiler;
|
|
21
22
|
const nodes = tree.allNodes();
|
|
22
23
|
const extract = {};
|
|
@@ -27,6 +28,9 @@ class ExtractTSStage {
|
|
|
27
28
|
machines: {}
|
|
28
29
|
};
|
|
29
30
|
nodes.forEach(node => {
|
|
31
|
+
if (node.progressive) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
30
34
|
if (node.isInline) {
|
|
31
35
|
return;
|
|
32
36
|
}
|
|
@@ -46,6 +50,9 @@ class ExtractTSStage {
|
|
|
46
50
|
Object.assign(organized.machines, nodeOrganized.machines);
|
|
47
51
|
});
|
|
48
52
|
nodes.forEach(node => {
|
|
53
|
+
if (node.progressive) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
49
56
|
const imports = node.isInline
|
|
50
57
|
? extract[node.root.tag]?.imports
|
|
51
58
|
: extract[node.tag]?.imports;
|
|
@@ -68,6 +75,8 @@ class ExtractTSStage {
|
|
|
68
75
|
appDependencies: [] // TODO
|
|
69
76
|
};
|
|
70
77
|
});
|
|
78
|
+
const t = new Date().getTime();
|
|
79
|
+
log_1.Log.debug('compiler', 'stage.extract_ts', `[t: ${(t - t0) / 1000} ms]`);
|
|
71
80
|
log_1.Log.trace('compiler', 'stage.extract_ts', 'Finished extracting TS code', organized);
|
|
72
81
|
}
|
|
73
82
|
}
|