@shuvi/service 0.0.1-pre.1
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/api/api.d.ts +75 -0
- package/lib/api/api.js +370 -0
- package/lib/api/index.d.ts +6 -0
- package/lib/api/index.js +4 -0
- package/lib/api/initCoreResource.d.ts +2 -0
- package/lib/api/initCoreResource.js +27 -0
- package/lib/api/paths.d.ts +8 -0
- package/lib/api/paths.js +20 -0
- package/lib/api/plugin.d.ts +6 -0
- package/lib/api/plugin.js +108 -0
- package/lib/api/pluginApi.d.ts +29 -0
- package/lib/api/pluginApi.js +44 -0
- package/lib/api/setupApp.d.ts +2 -0
- package/lib/api/setupApp.js +132 -0
- package/lib/api/types.d.ts +152 -0
- package/lib/api/types.js +2 -0
- package/lib/bundler/bundler.d.ts +33 -0
- package/lib/bundler/bundler.js +293 -0
- package/lib/bundler/config.d.ts +18 -0
- package/lib/bundler/config.js +85 -0
- package/lib/bundler/index.d.ts +2 -0
- package/lib/bundler/index.js +4 -0
- package/lib/bundler/runCompiler.d.ts +7 -0
- package/lib/bundler/runCompiler.js +43 -0
- package/lib/cli/build.d.ts +8 -0
- package/lib/cli/build.js +90 -0
- package/lib/config/index.d.ts +8 -0
- package/lib/config/index.js +50 -0
- package/lib/config/loadDotenvConfig.d.ts +1 -0
- package/lib/config/loadDotenvConfig.js +50 -0
- package/lib/constants.d.ts +14 -0
- package/lib/constants.js +20 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.js +21 -0
- package/lib/lib/apiRouteHandler.d.ts +80 -0
- package/lib/lib/apiRouteHandler.js +216 -0
- package/lib/lib/apiRoutes.d.ts +11 -0
- package/lib/lib/apiRoutes.js +76 -0
- package/lib/lib/devMiddleware.d.ts +10 -0
- package/lib/lib/devMiddleware.js +81 -0
- package/lib/lib/getPlatform.d.ts +2 -0
- package/lib/lib/getPlatform.js +8 -0
- package/lib/lib/getPublicRuntimeConfig.d.ts +2 -0
- package/lib/lib/getPublicRuntimeConfig.js +14 -0
- package/lib/lib/hotMiddleware.d.ts +31 -0
- package/lib/lib/hotMiddleware.js +123 -0
- package/lib/lib/httpProxyMiddleware.d.ts +7 -0
- package/lib/lib/httpProxyMiddleware.js +49 -0
- package/lib/lib/initRuntime.d.ts +5 -0
- package/lib/lib/initRuntime.js +16 -0
- package/lib/lib/launchEditorMiddleware.d.ts +2 -0
- package/lib/lib/launchEditorMiddleware.js +39 -0
- package/lib/lib/matchRoutes.d.ts +2 -0
- package/lib/lib/matchRoutes.js +8 -0
- package/lib/lib/onDemandRouteManager.d.ts +11 -0
- package/lib/lib/onDemandRouteManager.js +69 -0
- package/lib/lib/renderToHTML.d.ts +10 -0
- package/lib/lib/renderToHTML.js +52 -0
- package/lib/lib/resolveRuntimeCoreFile.d.ts +2 -0
- package/lib/lib/resolveRuntimeCoreFile.js +17 -0
- package/lib/lib/routes.d.ts +12 -0
- package/lib/lib/routes.js +90 -0
- package/lib/lib/runtimeConfig.d.ts +4 -0
- package/lib/lib/runtimeConfig.js +10 -0
- package/lib/lib/serveStatic.d.ts +3 -0
- package/lib/lib/serveStatic.js +24 -0
- package/lib/lib/utils.d.ts +6 -0
- package/lib/lib/utils.js +25 -0
- package/lib/lib/viewTemplate.d.ts +5 -0
- package/lib/lib/viewTemplate.js +16 -0
- package/lib/project/file-manager/errorHandling.d.ts +1 -0
- package/lib/project/file-manager/errorHandling.js +13 -0
- package/lib/project/file-manager/file.d.ts +17 -0
- package/lib/project/file-manager/file.js +146 -0
- package/lib/project/file-manager/fileManager.d.ts +11 -0
- package/lib/project/file-manager/fileManager.js +86 -0
- package/lib/project/file-manager/fileTypes.d.ts +56 -0
- package/lib/project/file-manager/fileTypes.js +2 -0
- package/lib/project/file-manager/index.d.ts +7 -0
- package/lib/project/file-manager/index.js +9 -0
- package/lib/project/file-manager/lifecycle.d.ts +7 -0
- package/lib/project/file-manager/lifecycle.js +42 -0
- package/lib/project/file-manager/mount.d.ts +3 -0
- package/lib/project/file-manager/mount.js +80 -0
- package/lib/project/file-manager/scheduler.d.ts +35 -0
- package/lib/project/file-manager/scheduler.js +169 -0
- package/lib/project/file-manager/utils.d.ts +1 -0
- package/lib/project/file-manager/utils.js +7 -0
- package/lib/project/file-presets/files/core/404.js.d.ts +4 -0
- package/lib/project/file-presets/files/core/404.js.js +9 -0
- package/lib/project/file-presets/files/core/apiRoutes.js.d.ts +5 -0
- package/lib/project/file-presets/files/core/apiRoutes.js.js +5 -0
- package/lib/project/file-presets/files/core/app.js.d.ts +4 -0
- package/lib/project/file-presets/files/core/app.js.js +9 -0
- package/lib/project/file-presets/files/core/client/application.js.d.ts +5 -0
- package/lib/project/file-presets/files/core/client/application.js.js +7 -0
- package/lib/project/file-presets/files/core/client/entry.js.d.ts +5 -0
- package/lib/project/file-presets/files/core/client/entry.js.js +7 -0
- package/lib/project/file-presets/files/core/platform.js.d.ts +5 -0
- package/lib/project/file-presets/files/core/platform.js.js +7 -0
- package/lib/project/file-presets/files/core/plugins.js.d.ts +5 -0
- package/lib/project/file-presets/files/core/plugins.js.js +16 -0
- package/lib/project/file-presets/files/core/polyfill.js.d.ts +5 -0
- package/lib/project/file-presets/files/core/polyfill.js.js +5 -0
- package/lib/project/file-presets/files/core/routes.js.d.ts +5 -0
- package/lib/project/file-presets/files/core/routes.js.js +5 -0
- package/lib/project/file-presets/files/core/runtimeConfig.js.d.ts +5 -0
- package/lib/project/file-presets/files/core/runtimeConfig.js.js +5 -0
- package/lib/project/file-presets/files/core/server/application.js.d.ts +5 -0
- package/lib/project/file-presets/files/core/server/application.js.js +7 -0
- package/lib/project/file-presets/files/core/setRuntimeConfig.js.d.ts +4 -0
- package/lib/project/file-presets/files/core/setRuntimeConfig.js.js +5 -0
- package/lib/project/file-presets/files/entry.client-wrapper.js.d.ts +5 -0
- package/lib/project/file-presets/files/entry.client-wrapper.js.js +5 -0
- package/lib/project/file-presets/files/entry.client.js.d.ts +5 -0
- package/lib/project/file-presets/files/entry.client.js.js +25 -0
- package/lib/project/file-presets/files/entry.server.js.d.ts +5 -0
- package/lib/project/file-presets/files/entry.server.js.js +6 -0
- package/lib/project/file-presets/files/index.d.ts.d.ts +5 -0
- package/lib/project/file-presets/files/index.d.ts.js +6 -0
- package/lib/project/file-presets/files/index.js.d.ts +5 -0
- package/lib/project/file-presets/files/index.js.js +6 -0
- package/lib/project/file-presets/files/main.server.js.d.ts +4 -0
- package/lib/project/file-presets/files/main.server.js.js +13 -0
- package/lib/project/file-presets/files/user/404.js.d.ts +7 -0
- package/lib/project/file-presets/files/user/404.js.js +9 -0
- package/lib/project/file-presets/files/user/app.js.d.ts +7 -0
- package/lib/project/file-presets/files/user/app.js.js +9 -0
- package/lib/project/file-presets/files/user/document.js.d.ts +7 -0
- package/lib/project/file-presets/files/user/document.js.js +9 -0
- package/lib/project/file-presets/files/user/plugin.js.d.ts +7 -0
- package/lib/project/file-presets/files/user/plugin.js.js +9 -0
- package/lib/project/file-presets/files/user/server.js.d.ts +7 -0
- package/lib/project/file-presets/files/user/server.js.js +9 -0
- package/lib/project/file-presets/index.d.ts +2 -0
- package/lib/project/file-presets/index.js +33 -0
- package/lib/project/file-snippets/helpers.d.ts +9 -0
- package/lib/project/file-snippets/helpers.js +72 -0
- package/lib/project/file-snippets/index.d.ts +15 -0
- package/lib/project/file-snippets/index.js +22 -0
- package/lib/project/file-snippets/moduleExportProxy.d.ts +9 -0
- package/lib/project/file-snippets/moduleExportProxy.js +124 -0
- package/lib/project/index.d.ts +3 -0
- package/lib/project/index.js +15 -0
- package/lib/project/projectBuilder.d.ts +36 -0
- package/lib/project/projectBuilder.js +199 -0
- package/lib/project/projectContext.d.ts +66 -0
- package/lib/project/projectContext.js +30 -0
- package/lib/renderer/base.d.ts +22 -0
- package/lib/renderer/base.js +147 -0
- package/lib/renderer/htmlTag.d.ts +4 -0
- package/lib/renderer/htmlTag.js +69 -0
- package/lib/renderer/index.d.ts +11 -0
- package/lib/renderer/index.js +20 -0
- package/lib/renderer/spa.d.ts +10 -0
- package/lib/renderer/spa.js +20 -0
- package/lib/renderer/ssr.d.ts +15 -0
- package/lib/renderer/ssr.js +76 -0
- package/lib/renderer/types.d.ts +14 -0
- package/lib/renderer/types.js +2 -0
- package/lib/route/index.d.ts +1 -0
- package/lib/route/index.js +4 -0
- package/lib/route/parseDynamicPath.d.ts +1 -0
- package/lib/route/parseDynamicPath.js +42 -0
- package/lib/route/route.d.ts +13 -0
- package/lib/route/route.js +161 -0
- package/lib/server/index.d.ts +2 -0
- package/lib/server/index.js +4 -0
- package/lib/server/router.d.ts +14 -0
- package/lib/server/router.js +111 -0
- package/lib/server/server.d.ts +17 -0
- package/lib/server/server.js +139 -0
- package/lib/server/serverTypes.d.ts +9 -0
- package/lib/server/serverTypes.js +2 -0
- package/lib/shuvi/index.d.ts +10 -0
- package/lib/shuvi/index.js +18 -0
- package/lib/shuvi/shuvi.base.d.ts +26 -0
- package/lib/shuvi/shuvi.base.js +152 -0
- package/lib/shuvi/shuvi.dev.d.ts +9 -0
- package/lib/shuvi/shuvi.dev.js +94 -0
- package/lib/shuvi/shuvi.prod.d.ts +6 -0
- package/lib/shuvi/shuvi.prod.js +55 -0
- package/lib/types/bundler.d.ts +1 -0
- package/lib/types/bundler.js +10 -0
- package/lib/types/hooks.d.ts +67 -0
- package/lib/types/hooks.js +2 -0
- package/lib/types/index.d.ts +3 -0
- package/lib/types/index.js +12 -0
- package/lib/types/runtime.d.ts +168 -0
- package/lib/types/runtime.js +2 -0
- package/package.json +65 -0
- package/types/app-env.d.ts +66 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const path_1 = __importDefault(require("path"));
|
|
16
|
+
const mount_1 = require("./mount");
|
|
17
|
+
const scheduler_1 = require("./scheduler");
|
|
18
|
+
function getFileManager({ watch = false, context }) {
|
|
19
|
+
let hasMounted = false;
|
|
20
|
+
let hasUnMounted = false;
|
|
21
|
+
let rootDir = '';
|
|
22
|
+
const files = [];
|
|
23
|
+
const instances = new Map();
|
|
24
|
+
const addFile = (options) => {
|
|
25
|
+
if (hasUnMounted) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
files.push(Object.assign(Object.assign({}, options), { name: options.name }));
|
|
29
|
+
if (hasMounted) {
|
|
30
|
+
scheduler_1.queueJob(() => {
|
|
31
|
+
mount(rootDir);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const _mountFile = (file) => __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
try {
|
|
37
|
+
const inst = yield mount_1.mount(file, context, watch);
|
|
38
|
+
instances.set(file.name, inst);
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
console.log(`fail to mount file ${file.name}`);
|
|
42
|
+
console.error(error);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
const mount = (dir) => __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
// rootDir is set while mounting
|
|
47
|
+
rootDir = dir;
|
|
48
|
+
if (!hasMounted) {
|
|
49
|
+
hasMounted = true;
|
|
50
|
+
}
|
|
51
|
+
const tasks = [];
|
|
52
|
+
const filesCopy = files.slice();
|
|
53
|
+
files.length = 0;
|
|
54
|
+
for (const file of filesCopy) {
|
|
55
|
+
// rootDir as well as Full path name would not be set until mount
|
|
56
|
+
file.name = path_1.default.resolve(rootDir, file.name);
|
|
57
|
+
tasks.push(() => _mountFile(file));
|
|
58
|
+
}
|
|
59
|
+
yield Promise.all(tasks.map(task => task()));
|
|
60
|
+
});
|
|
61
|
+
const unmount = () => __awaiter(this, void 0, void 0, function* () {
|
|
62
|
+
const tasks = [];
|
|
63
|
+
for (const [name, inst] of instances.entries()) {
|
|
64
|
+
tasks.push(() => __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
try {
|
|
66
|
+
yield inst.destroy();
|
|
67
|
+
instances.delete(name);
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
console.log(`fail to unmount file ${name}`);
|
|
71
|
+
console.error(error);
|
|
72
|
+
}
|
|
73
|
+
}));
|
|
74
|
+
}
|
|
75
|
+
yield Promise.all(tasks.map(task => task()));
|
|
76
|
+
instances.clear();
|
|
77
|
+
hasMounted = false;
|
|
78
|
+
hasUnMounted = true;
|
|
79
|
+
});
|
|
80
|
+
return {
|
|
81
|
+
addFile,
|
|
82
|
+
mount,
|
|
83
|
+
unmount
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
exports.getFileManager = getFileManager;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { ReactiveEffect } from '@vue/reactivity';
|
|
2
|
+
export declare type FileLifecycleHooks = 'mounted' | 'unmounted';
|
|
3
|
+
export declare type Data = Record<string, unknown>;
|
|
4
|
+
export interface MethodOptions {
|
|
5
|
+
[key: string]: Function;
|
|
6
|
+
}
|
|
7
|
+
export interface FileInternalOptions {
|
|
8
|
+
}
|
|
9
|
+
export interface FileOptionsBase<Data, Method extends MethodOptions> extends FileInternalOptions {
|
|
10
|
+
name: string;
|
|
11
|
+
content: (this: CreateFilePublicInstance<Data, Method>, ctx: any) => string | null | undefined;
|
|
12
|
+
setup?: (this: void) => Data | void;
|
|
13
|
+
methods?: Method;
|
|
14
|
+
mounted?(): void;
|
|
15
|
+
unmounted?(): void;
|
|
16
|
+
[key: string]: any;
|
|
17
|
+
}
|
|
18
|
+
export declare type FileOptions<Data = any, Method extends MethodOptions = any> = FileOptionsBase<Data, Method> & ThisType<CreateFilePublicInstance<Data, Method>>;
|
|
19
|
+
export declare type FilePublicInstance<Data = {}, // return from data()
|
|
20
|
+
Context = {}, Method extends MethodOptions = {}> = {
|
|
21
|
+
$setup: Data;
|
|
22
|
+
$context: Context;
|
|
23
|
+
} & Data & Context & Method;
|
|
24
|
+
export declare type CreateFilePublicInstance<Data = {}, Context = {}, Method extends MethodOptions = {}> = FilePublicInstance<Data, Context, Method>;
|
|
25
|
+
export declare type FileInternalContentFunction = (ctx: any, $setup: Data) => string;
|
|
26
|
+
export declare type FileType<Data = any, Method extends MethodOptions = MethodOptions> = FileOptions<Data, Method>;
|
|
27
|
+
export interface FileInternalInstance {
|
|
28
|
+
name: string;
|
|
29
|
+
type: FileType;
|
|
30
|
+
effects?: ReactiveEffect[];
|
|
31
|
+
/**
|
|
32
|
+
* The reactive effect for rendering and patching the component. Callable.
|
|
33
|
+
*/
|
|
34
|
+
update: any;
|
|
35
|
+
destroy: any;
|
|
36
|
+
/**
|
|
37
|
+
* The render function that returns vdom tree.
|
|
38
|
+
*/
|
|
39
|
+
content: FileInternalContentFunction;
|
|
40
|
+
/**
|
|
41
|
+
* cache for proxy access type to avoid hasOwnProperty calls
|
|
42
|
+
*/
|
|
43
|
+
accessCache: Data | null;
|
|
44
|
+
proxy: FilePublicInstance | null;
|
|
45
|
+
/**
|
|
46
|
+
* This is the target for the public instance proxy. It also holds properties
|
|
47
|
+
* injected by user options (computed, methods etc.) and user-attached
|
|
48
|
+
* custom properties (via `this.x = ...`)
|
|
49
|
+
*/
|
|
50
|
+
ctx: Data;
|
|
51
|
+
setupState: Data;
|
|
52
|
+
isMounted: boolean;
|
|
53
|
+
isUnmounted: boolean;
|
|
54
|
+
mounted: Function[];
|
|
55
|
+
unmounted: Function[];
|
|
56
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { reactive } from '@vue/reactivity';
|
|
2
|
+
import { getFileManager, FileManager } from './fileManager';
|
|
3
|
+
export type { FileOptions } from './file';
|
|
4
|
+
export { onMounted, onUnmounted } from './lifecycle';
|
|
5
|
+
export { reactive };
|
|
6
|
+
export { getFileManager };
|
|
7
|
+
export type { FileManager };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const reactivity_1 = require("@vue/reactivity");
|
|
4
|
+
exports.reactive = reactivity_1.reactive;
|
|
5
|
+
const fileManager_1 = require("./fileManager");
|
|
6
|
+
exports.getFileManager = fileManager_1.getFileManager;
|
|
7
|
+
var lifecycle_1 = require("./lifecycle");
|
|
8
|
+
exports.onMounted = lifecycle_1.onMounted;
|
|
9
|
+
exports.onUnmounted = lifecycle_1.onUnmounted;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { FileLifecycleHooks, FileInternalInstance } from './file';
|
|
2
|
+
export declare function injectHook(type: FileLifecycleHooks, hook: Function & {
|
|
3
|
+
__weh?: Function;
|
|
4
|
+
}, target?: FileInternalInstance | null, prepend?: boolean): Function | undefined;
|
|
5
|
+
export declare const createHook: <T extends Function = () => any>(lifecycle: FileLifecycleHooks) => (hook: T, target?: FileInternalInstance | null) => Function | undefined;
|
|
6
|
+
export declare const onMounted: (hook: () => any, target?: FileInternalInstance | null) => Function | undefined;
|
|
7
|
+
export declare const onUnmounted: (hook: () => any, target?: FileInternalInstance | null) => Function | undefined;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const reactivity_1 = require("@vue/reactivity");
|
|
4
|
+
const errorHandling_1 = require("./errorHandling");
|
|
5
|
+
const file_1 = require("./file");
|
|
6
|
+
function injectHook(type, hook, target = file_1.currentInstance, prepend = false) {
|
|
7
|
+
if (target) {
|
|
8
|
+
const hooks = target[type] || (target[type] = []);
|
|
9
|
+
// cache the error handling wrapper for injected hooks so the same hook
|
|
10
|
+
// can be properly deduped by the scheduler. "__weh" stands for "with error
|
|
11
|
+
// handling".
|
|
12
|
+
const wrappedHook = hook.__weh ||
|
|
13
|
+
(hook.__weh = (...args) => {
|
|
14
|
+
if (target.isUnmounted) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
// disable tracking inside all lifecycle hooks
|
|
18
|
+
// since they can potentially be called inside effects.
|
|
19
|
+
reactivity_1.pauseTracking();
|
|
20
|
+
// Set currentInstance during hook invocation.
|
|
21
|
+
// This assumes the hook does not synchronously trigger other hooks, which
|
|
22
|
+
// can only be false when the user does something really funky.
|
|
23
|
+
file_1.setCurrentInstance(target);
|
|
24
|
+
const res = errorHandling_1.callWithErrorHandling(hook, args);
|
|
25
|
+
file_1.setCurrentInstance(null);
|
|
26
|
+
reactivity_1.resetTracking();
|
|
27
|
+
return res;
|
|
28
|
+
});
|
|
29
|
+
if (prepend) {
|
|
30
|
+
hooks.unshift(wrappedHook);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
hooks.push(wrappedHook);
|
|
34
|
+
}
|
|
35
|
+
return wrappedHook;
|
|
36
|
+
}
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
exports.injectHook = injectHook;
|
|
40
|
+
exports.createHook = (lifecycle) => (hook, target = file_1.currentInstance) => injectHook(lifecycle, hook, target);
|
|
41
|
+
exports.onMounted = exports.createHook('mounted');
|
|
42
|
+
exports.onUnmounted = exports.createHook('unmounted');
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const path_1 = __importDefault(require("path"));
|
|
7
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
|
+
const utils_1 = require("@shuvi/utils");
|
|
9
|
+
const reactivity_1 = require("@vue/reactivity");
|
|
10
|
+
const file_1 = require("./file");
|
|
11
|
+
const scheduler_1 = require("./scheduler");
|
|
12
|
+
const utils_2 = require("./utils");
|
|
13
|
+
function mount(options, context = {}, watch) {
|
|
14
|
+
const defer = utils_1.Defer();
|
|
15
|
+
const instance = file_1.createFileInstance(options);
|
|
16
|
+
const { content, name: fsPath, setupState } = instance;
|
|
17
|
+
const dir = path_1.default.dirname(fsPath);
|
|
18
|
+
let fd;
|
|
19
|
+
const componentEffect = () => {
|
|
20
|
+
// mount
|
|
21
|
+
if (!instance.isMounted) {
|
|
22
|
+
fs_extra_1.default.ensureDirSync(dir);
|
|
23
|
+
fd = fs_extra_1.default.openSync(fsPath, 'w+');
|
|
24
|
+
const fileContent = content(context, setupState);
|
|
25
|
+
if (fileContent != undefined) {
|
|
26
|
+
fs_extra_1.default.writeSync(fd, fileContent, 0);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* `mounted` hook could be excuted only in watch mode
|
|
30
|
+
*/
|
|
31
|
+
if (watch) {
|
|
32
|
+
utils_2.invokeArrayFns(instance.mounted);
|
|
33
|
+
}
|
|
34
|
+
instance.isMounted = true;
|
|
35
|
+
defer.resolve(instance);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const fileContent = content(context, setupState);
|
|
39
|
+
fs_extra_1.default.ftruncateSync(fd, 0);
|
|
40
|
+
fs_extra_1.default.writeSync(fd, fileContent, 0);
|
|
41
|
+
};
|
|
42
|
+
if (watch) {
|
|
43
|
+
instance.update = reactivity_1.effect(componentEffect, {
|
|
44
|
+
scheduler: scheduler_1.queueJob,
|
|
45
|
+
allowRecurse: true
|
|
46
|
+
// lazy: true,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
componentEffect();
|
|
51
|
+
}
|
|
52
|
+
instance.destroy = () => {
|
|
53
|
+
const destroyDefer = utils_1.Defer();
|
|
54
|
+
const { effects, update, unmounted, name: fsPath } = instance;
|
|
55
|
+
fs_extra_1.default.removeSync(fsPath);
|
|
56
|
+
if (effects) {
|
|
57
|
+
for (let i = 0; i < effects.length; i++) {
|
|
58
|
+
reactivity_1.stop(effects[i]);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (update) {
|
|
62
|
+
reactivity_1.stop(update);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* `unmounted` hook could be excuted only in watch mode
|
|
66
|
+
*/
|
|
67
|
+
if (watch) {
|
|
68
|
+
scheduler_1.queuePostFlushCb(() => {
|
|
69
|
+
utils_2.invokeArrayFns(unmounted);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
scheduler_1.queuePostFlushCb(() => {
|
|
73
|
+
instance.isUnmounted = true;
|
|
74
|
+
destroyDefer.resolve();
|
|
75
|
+
});
|
|
76
|
+
return destroyDefer.promise;
|
|
77
|
+
};
|
|
78
|
+
return defer.promise;
|
|
79
|
+
}
|
|
80
|
+
exports.mount = mount;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { FilePublicInstance } from './fileTypes';
|
|
2
|
+
export interface SchedulerJob {
|
|
3
|
+
(): void;
|
|
4
|
+
/**
|
|
5
|
+
* unique job id, only present on raw effects, e.g. component render effect
|
|
6
|
+
*/
|
|
7
|
+
id?: number;
|
|
8
|
+
/**
|
|
9
|
+
* Indicates whether the job is allowed to recursively trigger itself.
|
|
10
|
+
* By default, a job cannot trigger itself because some built-in method calls,
|
|
11
|
+
* e.g. Array.prototype.push actually performs reads as well (#1740) which
|
|
12
|
+
* can lead to confusing infinite loops.
|
|
13
|
+
* The allowed cases are component update functions and watch callbacks.
|
|
14
|
+
* Component update functions may update child component props, which in turn
|
|
15
|
+
* trigger flush: "pre" watch callbacks that mutates state that the parent
|
|
16
|
+
* relies on (#1801). Watch callbacks doesn't track its dependencies so if it
|
|
17
|
+
* triggers itself again, it's likely intentional and it is the user's
|
|
18
|
+
* responsibility to perform recursive state mutation that eventually
|
|
19
|
+
* stabilizes (#1727).
|
|
20
|
+
*/
|
|
21
|
+
allowRecurse?: boolean;
|
|
22
|
+
}
|
|
23
|
+
export declare type SchedulerCb = Function & {
|
|
24
|
+
id?: number;
|
|
25
|
+
};
|
|
26
|
+
export declare type SchedulerCbs = SchedulerCb | SchedulerCb[];
|
|
27
|
+
declare type CountMap = Map<SchedulerJob | SchedulerCb, number>;
|
|
28
|
+
export declare function nextTick(this: FilePublicInstance | void, fn?: () => void): Promise<void>;
|
|
29
|
+
export declare function queueJob(job: SchedulerJob): void;
|
|
30
|
+
export declare function invalidateJob(job: SchedulerJob): void;
|
|
31
|
+
export declare function queuePreFlushCb(cb: SchedulerCb): void;
|
|
32
|
+
export declare function queuePostFlushCb(cb: SchedulerCbs): void;
|
|
33
|
+
export declare function flushPreFlushCbs(seen?: CountMap, parentJob?: SchedulerJob | null): void;
|
|
34
|
+
export declare function flushPostFlushCbs(seen?: CountMap): void;
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const errorHandling_1 = require("./errorHandling");
|
|
4
|
+
const utils_1 = require("@shuvi/utils");
|
|
5
|
+
let isFlushing = false;
|
|
6
|
+
let isFlushPending = false;
|
|
7
|
+
const queue = [];
|
|
8
|
+
let flushIndex = 0;
|
|
9
|
+
const pendingPreFlushCbs = [];
|
|
10
|
+
let activePreFlushCbs = null;
|
|
11
|
+
let preFlushIndex = 0;
|
|
12
|
+
const pendingPostFlushCbs = [];
|
|
13
|
+
let activePostFlushCbs = null;
|
|
14
|
+
let postFlushIndex = 0;
|
|
15
|
+
const resolvedPromise = Promise.resolve();
|
|
16
|
+
let currentFlushPromise = null;
|
|
17
|
+
let currentPreFlushParentJob = null;
|
|
18
|
+
const RECURSION_LIMIT = 100;
|
|
19
|
+
const getId = (job) => job.id == null ? Infinity : job.id;
|
|
20
|
+
function nextTick(fn) {
|
|
21
|
+
const p = currentFlushPromise || resolvedPromise;
|
|
22
|
+
return fn ? p.then(this ? fn.bind(this) : fn) : p;
|
|
23
|
+
}
|
|
24
|
+
exports.nextTick = nextTick;
|
|
25
|
+
function queueJob(job) {
|
|
26
|
+
// the dedupe search uses the startIndex argument of Array.includes()
|
|
27
|
+
// by default the search index includes the current job that is being run
|
|
28
|
+
// so it cannot recursively trigger itself again.
|
|
29
|
+
// if the job is a watch() callback, the search will start with a +1 index to
|
|
30
|
+
// allow it recursively trigger itself - it is the user's responsibility to
|
|
31
|
+
// ensure it doesn't end up in an infinite loop.
|
|
32
|
+
if ((!queue.length ||
|
|
33
|
+
!queue.includes(job, isFlushing && job.allowRecurse ? flushIndex + 1 : flushIndex)) &&
|
|
34
|
+
job !== currentPreFlushParentJob) {
|
|
35
|
+
queue.push(job);
|
|
36
|
+
queueFlush();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.queueJob = queueJob;
|
|
40
|
+
function queueFlush() {
|
|
41
|
+
if (!isFlushing && !isFlushPending) {
|
|
42
|
+
isFlushPending = true;
|
|
43
|
+
currentFlushPromise = resolvedPromise.then(flushJobs);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function invalidateJob(job) {
|
|
47
|
+
const i = queue.indexOf(job);
|
|
48
|
+
if (i > -1) {
|
|
49
|
+
queue[i] = null;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.invalidateJob = invalidateJob;
|
|
53
|
+
function queueCb(cb, activeQueue, pendingQueue, index) {
|
|
54
|
+
if (!utils_1.isArray(cb)) {
|
|
55
|
+
if (!activeQueue ||
|
|
56
|
+
!activeQueue.includes(cb, cb.allowRecurse ? index + 1 : index)) {
|
|
57
|
+
pendingQueue.push(cb);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
// if cb is an array, it is a component lifecycle hook which can only be
|
|
62
|
+
// triggered by a job, which is already deduped in the main queue, so
|
|
63
|
+
// we can skip duplicate check here to improve perf
|
|
64
|
+
pendingQueue.push(...cb);
|
|
65
|
+
}
|
|
66
|
+
queueFlush();
|
|
67
|
+
}
|
|
68
|
+
function queuePreFlushCb(cb) {
|
|
69
|
+
queueCb(cb, activePreFlushCbs, pendingPreFlushCbs, preFlushIndex);
|
|
70
|
+
}
|
|
71
|
+
exports.queuePreFlushCb = queuePreFlushCb;
|
|
72
|
+
function queuePostFlushCb(cb) {
|
|
73
|
+
queueCb(cb, activePostFlushCbs, pendingPostFlushCbs, postFlushIndex);
|
|
74
|
+
}
|
|
75
|
+
exports.queuePostFlushCb = queuePostFlushCb;
|
|
76
|
+
function flushPreFlushCbs(seen, parentJob = null) {
|
|
77
|
+
if (pendingPreFlushCbs.length) {
|
|
78
|
+
currentPreFlushParentJob = parentJob;
|
|
79
|
+
activePreFlushCbs = [...new Set(pendingPreFlushCbs)];
|
|
80
|
+
pendingPreFlushCbs.length = 0;
|
|
81
|
+
seen = seen || new Map();
|
|
82
|
+
for (preFlushIndex = 0; preFlushIndex < activePreFlushCbs.length; preFlushIndex++) {
|
|
83
|
+
checkRecursiveUpdates(seen, activePreFlushCbs[preFlushIndex]);
|
|
84
|
+
activePreFlushCbs[preFlushIndex]();
|
|
85
|
+
}
|
|
86
|
+
activePreFlushCbs = null;
|
|
87
|
+
preFlushIndex = 0;
|
|
88
|
+
currentPreFlushParentJob = null;
|
|
89
|
+
// recursively flush until it drains
|
|
90
|
+
flushPreFlushCbs(seen, parentJob);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
exports.flushPreFlushCbs = flushPreFlushCbs;
|
|
94
|
+
function flushPostFlushCbs(seen) {
|
|
95
|
+
if (pendingPostFlushCbs.length) {
|
|
96
|
+
const deduped = [...new Set(pendingPostFlushCbs)];
|
|
97
|
+
pendingPostFlushCbs.length = 0;
|
|
98
|
+
// #1947 already has active queue, nested flushPostFlushCbs call
|
|
99
|
+
if (activePostFlushCbs) {
|
|
100
|
+
activePostFlushCbs.push(...deduped);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
activePostFlushCbs = deduped;
|
|
104
|
+
seen = seen || new Map();
|
|
105
|
+
activePostFlushCbs.sort((a, b) => getId(a) - getId(b));
|
|
106
|
+
for (postFlushIndex = 0; postFlushIndex < activePostFlushCbs.length; postFlushIndex++) {
|
|
107
|
+
checkRecursiveUpdates(seen, activePostFlushCbs[postFlushIndex]);
|
|
108
|
+
activePostFlushCbs[postFlushIndex]();
|
|
109
|
+
}
|
|
110
|
+
activePostFlushCbs = null;
|
|
111
|
+
postFlushIndex = 0;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
exports.flushPostFlushCbs = flushPostFlushCbs;
|
|
115
|
+
function flushJobs(seen) {
|
|
116
|
+
isFlushPending = false;
|
|
117
|
+
isFlushing = true;
|
|
118
|
+
seen = seen || new Map();
|
|
119
|
+
flushPreFlushCbs(seen);
|
|
120
|
+
// Sort queue before flush.
|
|
121
|
+
// This ensures that:
|
|
122
|
+
// 1. Components are updated from parent to child. (because parent is always
|
|
123
|
+
// created before the child so its render effect will have smaller
|
|
124
|
+
// priority number)
|
|
125
|
+
// 2. If a component is unmounted during a parent component's update,
|
|
126
|
+
// its update can be skipped.
|
|
127
|
+
// Jobs can never be null before flush starts, since they are only invalidated
|
|
128
|
+
// during execution of another flushed job.
|
|
129
|
+
queue.sort((a, b) => getId(a) - getId(b));
|
|
130
|
+
try {
|
|
131
|
+
for (flushIndex = 0; flushIndex < queue.length; flushIndex++) {
|
|
132
|
+
const job = queue[flushIndex];
|
|
133
|
+
if (job) {
|
|
134
|
+
checkRecursiveUpdates(seen, job);
|
|
135
|
+
errorHandling_1.callWithErrorHandling(job);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
finally {
|
|
140
|
+
flushIndex = 0;
|
|
141
|
+
queue.length = 0;
|
|
142
|
+
flushPostFlushCbs(seen);
|
|
143
|
+
isFlushing = false;
|
|
144
|
+
currentFlushPromise = null;
|
|
145
|
+
// some postFlushCb queued jobs!
|
|
146
|
+
// keep flushing until it drains.
|
|
147
|
+
if (queue.length || pendingPostFlushCbs.length) {
|
|
148
|
+
flushJobs(seen);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
function checkRecursiveUpdates(seen, fn) {
|
|
153
|
+
if (!seen.has(fn)) {
|
|
154
|
+
seen.set(fn, 1);
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
const count = seen.get(fn);
|
|
158
|
+
if (count > RECURSION_LIMIT) {
|
|
159
|
+
throw new Error(`Maximum recursive updates exceeded. ` +
|
|
160
|
+
`This means you have a reactive effect that is mutating its own ` +
|
|
161
|
+
`dependencies and thus recursively triggering itself. Possible sources ` +
|
|
162
|
+
`include component template, render function, updated hook or ` +
|
|
163
|
+
`watcher source function.`);
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
seen.set(fn, count + 1);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const invokeArrayFns: (fns: Function[], arg?: any) => void;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const content = `import user404 from '@shuvi/app/user/404'
|
|
4
|
+
import { page404 as platform404 } from '@shuvi/app/core/platform'
|
|
5
|
+
export default user404 || platform404
|
|
6
|
+
`;
|
|
7
|
+
exports.default = {
|
|
8
|
+
content: () => content
|
|
9
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const content = `import userApp from '@shuvi/app/user/app'
|
|
4
|
+
import { app as platformApp } from '@shuvi/app/core/platform'
|
|
5
|
+
export default userApp || platformApp
|
|
6
|
+
`;
|
|
7
|
+
exports.default = {
|
|
8
|
+
content: () => content
|
|
9
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const file_snippets_1 = require("../../../../file-snippets");
|
|
4
|
+
const moduleExportProxy = file_snippets_1.moduleExportProxyCreater();
|
|
5
|
+
exports.default = {
|
|
6
|
+
content: (context) => moduleExportProxy.getContent(context.clientModule.application)
|
|
7
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const file_snippets_1 = require("../../../../file-snippets");
|
|
4
|
+
const moduleExportProxy = file_snippets_1.moduleExportProxyCreater();
|
|
5
|
+
exports.default = {
|
|
6
|
+
content: (context) => moduleExportProxy.getContent(context.clientModule.entry)
|
|
7
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const file_snippets_1 = require("../../../file-snippets");
|
|
4
|
+
const moduleExportProxy = file_snippets_1.moduleExportProxyCreater();
|
|
5
|
+
exports.default = {
|
|
6
|
+
content: (context) => moduleExportProxy.getContent(context.platformModule)
|
|
7
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = {
|
|
4
|
+
content: (context) => {
|
|
5
|
+
const plugins = context.runtimePlugins;
|
|
6
|
+
let pluginRecord = '';
|
|
7
|
+
let content = '';
|
|
8
|
+
plugins.forEach((value, name) => {
|
|
9
|
+
content += `import ${name} from "${value}"\n`;
|
|
10
|
+
pluginRecord += `${name},`;
|
|
11
|
+
});
|
|
12
|
+
content += `const pluginRecord = {${pluginRecord}}\n`;
|
|
13
|
+
content += `export { pluginRecord };`;
|
|
14
|
+
return content;
|
|
15
|
+
}
|
|
16
|
+
};
|