@unpackjs/core 0.1.1 → 0.2.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/dist/config/index.d.ts +18 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +114 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/{cjs/index.js → index.js} +26 -4
- package/package.json +8 -8
- package/dist/cjs/index.d.ts +0 -3
- package/dist/cjs/index.d.ts.map +0 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type CliOptions, type UnpackConfig } from '@unpackjs/shared';
|
|
2
|
+
export declare function loadConfig({ root, cliOptions, }: {
|
|
3
|
+
root?: string;
|
|
4
|
+
cliOptions?: CliOptions;
|
|
5
|
+
}): Promise<UnpackConfig>;
|
|
6
|
+
export type ConfigParams = {
|
|
7
|
+
/** command 为 dev 时为 development, command 为 build 时为 production */
|
|
8
|
+
env: string;
|
|
9
|
+
command: 'dev' | 'build';
|
|
10
|
+
};
|
|
11
|
+
export type UnpackConfigAsyncFn = (params: ConfigParams) => Promise<UnpackConfig>;
|
|
12
|
+
export type UnpackConfigSyncFn = (params: ConfigParams) => UnpackConfig;
|
|
13
|
+
export type UnpackConfigExport = UnpackConfig | UnpackConfigSyncFn | UnpackConfigAsyncFn;
|
|
14
|
+
export declare function defineConfig(config: UnpackConfig): UnpackConfig;
|
|
15
|
+
export declare function defineConfig(config: UnpackConfigSyncFn): UnpackConfigSyncFn;
|
|
16
|
+
export declare function defineConfig(config: UnpackConfigAsyncFn): UnpackConfigAsyncFn;
|
|
17
|
+
export declare function defineConfig(config: UnpackConfigExport): UnpackConfigExport;
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,UAAU,EACf,KAAK,YAAY,EAIlB,MAAM,kBAAkB,CAAA;AAUzB,wBAAsB,UAAU,CAAC,EAC/B,IAAI,EACJ,UAAU,GACX,EAAE;IACD,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,UAAU,CAAC,EAAE,UAAU,CAAA;CACxB,GAAG,OAAO,CAAC,YAAY,CAAC,CAgCxB;AACD,MAAM,MAAM,YAAY,GAAG;IACzB,kEAAkE;IAClE,GAAG,EAAE,MAAM,CAAA;IACX,OAAO,EAAE,KAAK,GAAG,OAAO,CAAA;CACzB,CAAA;AACD,MAAM,MAAM,mBAAmB,GAAG,CAAC,MAAM,EAAE,YAAY,KAAK,OAAO,CAAC,YAAY,CAAC,CAAA;AAEjF,MAAM,MAAM,kBAAkB,GAAG,CAAC,MAAM,EAAE,YAAY,KAAK,YAAY,CAAA;AAEvE,MAAM,MAAM,kBAAkB,GAAG,YAAY,GAAG,kBAAkB,GAAG,mBAAmB,CAAA;AACxF,wBAAgB,YAAY,CAAC,MAAM,EAAE,YAAY,GAAG,YAAY,CAAA;AAChE,wBAAgB,YAAY,CAAC,MAAM,EAAE,kBAAkB,GAAG,kBAAkB,CAAA;AAC5E,wBAAgB,YAAY,CAAC,MAAM,EAAE,mBAAmB,GAAG,mBAAmB,CAAA;AAC9E,wBAAgB,YAAY,CAAC,MAAM,EAAE,kBAAkB,GAAG,kBAAkB,CAAA"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var config_exports = {};
|
|
29
|
+
__export(config_exports, {
|
|
30
|
+
defineConfig: () => defineConfig,
|
|
31
|
+
loadConfig: () => loadConfig
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(config_exports);
|
|
34
|
+
var import_shared = require("@unpackjs/shared");
|
|
35
|
+
var import_node_fs = __toESM(require("node:fs"));
|
|
36
|
+
var import_node_path = require("node:path");
|
|
37
|
+
const jiti = require("@unpackjs/shared/jiti")(__filename, {
|
|
38
|
+
esmResolve: true,
|
|
39
|
+
// disable require cache to support restart CLI and read the new config
|
|
40
|
+
requireCache: false,
|
|
41
|
+
interopDefault: true
|
|
42
|
+
});
|
|
43
|
+
const merge = require("@unpackjs/shared/deepmerge");
|
|
44
|
+
async function loadConfig({
|
|
45
|
+
root,
|
|
46
|
+
cliOptions
|
|
47
|
+
}) {
|
|
48
|
+
const configPath = resolveConfigPath(root, cliOptions?.config);
|
|
49
|
+
let userConfig = {};
|
|
50
|
+
if (configPath) {
|
|
51
|
+
userConfig = jiti(configPath);
|
|
52
|
+
if (typeof userConfig === "function") {
|
|
53
|
+
const params = {
|
|
54
|
+
env: (0, import_shared.getNodeEnv)(),
|
|
55
|
+
command: process.argv[2]
|
|
56
|
+
};
|
|
57
|
+
userConfig = await userConfig(params);
|
|
58
|
+
if (userConfig === void 0) {
|
|
59
|
+
throw new Error("Unpack config function must return a config object.");
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const parsedUserConfig = userConfig;
|
|
64
|
+
const defaultConfig = {
|
|
65
|
+
bundler: "webpack",
|
|
66
|
+
build: {
|
|
67
|
+
watch: false
|
|
68
|
+
},
|
|
69
|
+
server: {
|
|
70
|
+
port: 3e3,
|
|
71
|
+
open: false
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
if (cliOptions.watch)
|
|
75
|
+
(0, import_shared.setValueByPath)(parsedUserConfig, ["build", "watch"], cliOptions.watch);
|
|
76
|
+
if (cliOptions.port)
|
|
77
|
+
(0, import_shared.setValueByPath)(parsedUserConfig, ["server", "port"], cliOptions.port);
|
|
78
|
+
if (cliOptions.open)
|
|
79
|
+
(0, import_shared.setValueByPath)(parsedUserConfig, ["server", "open"], cliOptions.open);
|
|
80
|
+
return merge(defaultConfig, parsedUserConfig);
|
|
81
|
+
}
|
|
82
|
+
function defineConfig(config) {
|
|
83
|
+
return config;
|
|
84
|
+
}
|
|
85
|
+
function resolveConfigPath(root, customConfig) {
|
|
86
|
+
if (customConfig) {
|
|
87
|
+
const customConfigPath = (0, import_node_path.isAbsolute)(customConfig) ? customConfig : (0, import_node_path.join)(root, customConfig);
|
|
88
|
+
if (import_node_fs.default.existsSync(customConfigPath)) {
|
|
89
|
+
return customConfigPath;
|
|
90
|
+
}
|
|
91
|
+
import_shared.logger.warn(`Cannot find config file: ${customConfigPath}
|
|
92
|
+
`);
|
|
93
|
+
}
|
|
94
|
+
const CONFIG_FILES = [
|
|
95
|
+
"unpack.config.ts",
|
|
96
|
+
"unpack.config.js",
|
|
97
|
+
"unpack.config.mjs",
|
|
98
|
+
"unpack.config.cjs",
|
|
99
|
+
"unpack.config.mts",
|
|
100
|
+
"unpack.config.cts"
|
|
101
|
+
];
|
|
102
|
+
for (const file of CONFIG_FILES) {
|
|
103
|
+
const configFile = (0, import_node_path.join)(root, file);
|
|
104
|
+
if (import_node_fs.default.existsSync(configFile)) {
|
|
105
|
+
return configFile;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
111
|
+
0 && (module.exports = {
|
|
112
|
+
defineConfig,
|
|
113
|
+
loadConfig
|
|
114
|
+
});
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type CliOptions } from '@unpackjs/shared';
|
|
2
|
+
export { defineConfig } from './config';
|
|
3
|
+
export type CreateServiceOptions = {
|
|
4
|
+
command: 'build' | 'dev';
|
|
5
|
+
root: string;
|
|
6
|
+
cliOptions?: CliOptions;
|
|
7
|
+
};
|
|
8
|
+
export declare function createService({ command, root, cliOptions }: CreateServiceOptions): Promise<void>;
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAGhE,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAEvC,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,EAAE,OAAO,GAAG,KAAK,CAAA;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,CAAC,EAAE,UAAU,CAAA;CACxB,CAAA;AACD,wBAAsB,aAAa,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,oBAAoB,iBAmBtF"}
|
|
@@ -15,11 +15,33 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
15
|
return to;
|
|
16
16
|
};
|
|
17
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
|
|
19
|
-
// src/index.ts
|
|
20
18
|
var src_exports = {};
|
|
21
19
|
__export(src_exports, {
|
|
22
|
-
|
|
20
|
+
createService: () => createService,
|
|
21
|
+
defineConfig: () => import_config2.defineConfig
|
|
23
22
|
});
|
|
24
23
|
module.exports = __toCommonJS(src_exports);
|
|
25
|
-
var
|
|
24
|
+
var import_config = require("./config");
|
|
25
|
+
var import_bundler_webpack = require("@unpackjs/bundler-webpack");
|
|
26
|
+
var import_config2 = require("./config");
|
|
27
|
+
async function createService({ command, root, cliOptions }) {
|
|
28
|
+
const unpackConfig = await (0, import_config.loadConfig)({ root, cliOptions });
|
|
29
|
+
const bundlerMap = {
|
|
30
|
+
webpack: () => {
|
|
31
|
+
return {
|
|
32
|
+
build: () => {
|
|
33
|
+
(0, import_bundler_webpack.webpackBuild)({ root, unpackConfig });
|
|
34
|
+
},
|
|
35
|
+
dev: () => {
|
|
36
|
+
(0, import_bundler_webpack.webpackDev)({ root, unpackConfig });
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
bundlerMap[unpackConfig.bundler]()[command]();
|
|
42
|
+
}
|
|
43
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
44
|
+
0 && (module.exports = {
|
|
45
|
+
createService,
|
|
46
|
+
defineConfig
|
|
47
|
+
});
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unpackjs/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "",
|
|
5
|
-
"main": "dist/
|
|
6
|
-
"types": "dist/
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
7
|
"keywords": [],
|
|
8
8
|
"authors": [],
|
|
9
9
|
"license": "MIT",
|
|
@@ -14,12 +14,12 @@
|
|
|
14
14
|
"publishConfig": {
|
|
15
15
|
"access": "public"
|
|
16
16
|
},
|
|
17
|
-
"
|
|
18
|
-
"
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@unpackjs/bundler-webpack": "^0.1.0",
|
|
19
|
+
"@unpackjs/shared": "^0.1.0"
|
|
19
20
|
},
|
|
20
21
|
"scripts": {
|
|
21
|
-
"dev": "
|
|
22
|
-
"build": "
|
|
23
|
-
"build:deps": "father prebundle"
|
|
22
|
+
"dev": "modern build --watch",
|
|
23
|
+
"build": "modern build"
|
|
24
24
|
}
|
|
25
25
|
}
|
package/dist/cjs/index.d.ts
DELETED
package/dist/cjs/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,wBAA6B"}
|