@utoo/pack 0.0.1-alpha.39 → 0.0.1-alpha.41
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/cjs/build.js +7 -2
- package/cjs/dev.js +6 -1
- package/cjs/find-root.d.ts +4 -0
- package/cjs/find-root.js +75 -0
- package/cjs/index.d.ts +3 -0
- package/cjs/index.js +17 -0
- package/esm/build.js +7 -2
- package/esm/dev.js +6 -1
- package/esm/find-root.d.ts +4 -0
- package/esm/find-root.js +66 -0
- package/esm/index.d.ts +3 -0
- package/esm/index.js +3 -0
- package/package.json +10 -9
package/cjs/build.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.build = build;
|
|
4
4
|
const nanoid_1 = require("nanoid");
|
|
5
|
+
const find_root_1 = require("./find-root");
|
|
5
6
|
const project_1 = require("./project");
|
|
6
7
|
const util_1 = require("./util");
|
|
7
8
|
const webpackCompat_1 = require("./webpackCompat");
|
|
@@ -10,6 +11,10 @@ function build(options, projectPath, rootPath) {
|
|
|
10
11
|
const bundleOptions = options.compatMode
|
|
11
12
|
? (0, webpackCompat_1.compatOptionsFromWebpack)(options)
|
|
12
13
|
: options;
|
|
14
|
+
if (!rootPath) {
|
|
15
|
+
// help user to find the rootDir automatically.
|
|
16
|
+
rootPath = (0, find_root_1.findRootDir)(projectPath || process.cwd());
|
|
17
|
+
}
|
|
13
18
|
return buildInternal(bundleOptions, projectPath, rootPath);
|
|
14
19
|
}
|
|
15
20
|
async function buildInternal(bundleOptions, projectPath, rootPath) {
|
|
@@ -49,10 +54,10 @@ async function buildInternal(bundleOptions, projectPath, rootPath) {
|
|
|
49
54
|
}
|
|
50
55
|
}
|
|
51
56
|
if (topLevelWarnings.length > 0) {
|
|
52
|
-
console.warn(`
|
|
57
|
+
console.warn(`Utoopack build encountered ${topLevelWarnings.length} warnings:\n${topLevelWarnings.join("\n")}`);
|
|
53
58
|
}
|
|
54
59
|
if (topLevelErrors.length > 0) {
|
|
55
|
-
throw new Error(`
|
|
60
|
+
throw new Error(`Utoopack build failed with ${topLevelErrors.length} errors:\n${topLevelErrors.join("\n")}`);
|
|
56
61
|
}
|
|
57
62
|
await project.shutdown();
|
|
58
63
|
// TODO: Maybe run tasks in worker is a better way, see
|
package/cjs/dev.js
CHANGED
|
@@ -19,6 +19,7 @@ const net_1 = require("net");
|
|
|
19
19
|
const path_1 = __importDefault(require("path"));
|
|
20
20
|
const send_1 = __importDefault(require("send"));
|
|
21
21
|
const url_1 = __importDefault(require("url"));
|
|
22
|
+
const find_root_1 = require("./find-root");
|
|
22
23
|
const hmr_1 = require("./hmr");
|
|
23
24
|
const mkcert_1 = require("./mkcert");
|
|
24
25
|
const util_1 = require("./util");
|
|
@@ -28,6 +29,10 @@ function serve(options, projectPath, rootPath, serverOptions) {
|
|
|
28
29
|
const bundleOptions = options.compatMode
|
|
29
30
|
? (0, webpackCompat_1.compatOptionsFromWebpack)(options)
|
|
30
31
|
: options;
|
|
32
|
+
if (!rootPath) {
|
|
33
|
+
// help user to find the rootDir automatically
|
|
34
|
+
rootPath = (0, find_root_1.findRootDir)(projectPath || process.cwd());
|
|
35
|
+
}
|
|
31
36
|
return serveInternal(bundleOptions, projectPath, rootPath, serverOptions);
|
|
32
37
|
}
|
|
33
38
|
async function serveInternal(options, projectPath, rootPath, serverOptions) {
|
|
@@ -35,7 +40,7 @@ async function serveInternal(options, projectPath, rootPath, serverOptions) {
|
|
|
35
40
|
if (process.env.XCODE_PROFILE) {
|
|
36
41
|
await (0, xcodeProfile_1.xcodeProfilingReady)();
|
|
37
42
|
}
|
|
38
|
-
startServer({
|
|
43
|
+
await startServer({
|
|
39
44
|
hostname: (serverOptions === null || serverOptions === void 0 ? void 0 : serverOptions.hostname) || "localhost",
|
|
40
45
|
port: (serverOptions === null || serverOptions === void 0 ? void 0 : serverOptions.port) || 3000,
|
|
41
46
|
https: serverOptions === null || serverOptions === void 0 ? void 0 : serverOptions.https,
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function findRootLockFile(cwd: string): string | undefined;
|
|
2
|
+
export declare function findPackageJson(cwd: string): string | undefined;
|
|
3
|
+
export declare function findWorkspacesRoot(cwd: string): string;
|
|
4
|
+
export declare function findRootDir(cwd: string): string;
|
package/cjs/find-root.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
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
|
+
exports.findRootLockFile = findRootLockFile;
|
|
7
|
+
exports.findPackageJson = findPackageJson;
|
|
8
|
+
exports.findWorkspacesRoot = findWorkspacesRoot;
|
|
9
|
+
exports.findRootDir = findRootDir;
|
|
10
|
+
const find_up_1 = __importDefault(require("find-up"));
|
|
11
|
+
const fs_1 = require("fs");
|
|
12
|
+
const path_1 = require("path");
|
|
13
|
+
function findRootLockFile(cwd) {
|
|
14
|
+
return find_up_1.default.sync([
|
|
15
|
+
"pnpm-lock.yaml",
|
|
16
|
+
"package-lock.json",
|
|
17
|
+
"yarn.lock",
|
|
18
|
+
"bun.lock",
|
|
19
|
+
"bun.lockb",
|
|
20
|
+
], {
|
|
21
|
+
cwd,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
// compitable with tnpm
|
|
25
|
+
function findPackageJson(cwd) {
|
|
26
|
+
return find_up_1.default.sync(["package.json"], {
|
|
27
|
+
cwd,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
function isWorkspaceRoot(pkgPath) {
|
|
31
|
+
const pkgJson = (0, fs_1.readFileSync)(pkgPath, "utf-8");
|
|
32
|
+
const pkgJsonContent = JSON.parse(pkgJson);
|
|
33
|
+
return Boolean(pkgJsonContent.workspaces);
|
|
34
|
+
}
|
|
35
|
+
// refer from: https://github.com/umijs/mako/blob/next/crates/cli/src/helper/workspace.rs#L153
|
|
36
|
+
// TODO: 这块逻辑后续跟 utoo-pkg 使用一套方法
|
|
37
|
+
function findWorkspacesRoot(cwd) {
|
|
38
|
+
const pkgJson = findPackageJson(cwd);
|
|
39
|
+
if (!pkgJson)
|
|
40
|
+
return cwd;
|
|
41
|
+
const pkgJsonFiles = [pkgJson];
|
|
42
|
+
while (true) {
|
|
43
|
+
const lastPkgJson = pkgJsonFiles[pkgJsonFiles.length - 1];
|
|
44
|
+
const currentDir = (0, path_1.dirname)(lastPkgJson);
|
|
45
|
+
const parentDir = (0, path_1.dirname)(currentDir);
|
|
46
|
+
if (parentDir === currentDir)
|
|
47
|
+
break;
|
|
48
|
+
if (isWorkspaceRoot(lastPkgJson))
|
|
49
|
+
break;
|
|
50
|
+
const newPkgJson = findPackageJson(parentDir);
|
|
51
|
+
if (!newPkgJson)
|
|
52
|
+
break;
|
|
53
|
+
pkgJsonFiles.push(newPkgJson);
|
|
54
|
+
}
|
|
55
|
+
return (0, path_1.dirname)(pkgJsonFiles[pkgJsonFiles.length - 1]);
|
|
56
|
+
}
|
|
57
|
+
function findRootDir(cwd) {
|
|
58
|
+
const lockFile = findRootLockFile(cwd);
|
|
59
|
+
if (!lockFile)
|
|
60
|
+
return findWorkspacesRoot(cwd);
|
|
61
|
+
const lockFiles = [lockFile];
|
|
62
|
+
while (true) {
|
|
63
|
+
const lastLockFile = lockFiles[lockFiles.length - 1];
|
|
64
|
+
const currentDir = (0, path_1.dirname)(lastLockFile);
|
|
65
|
+
const parentDir = (0, path_1.dirname)(currentDir);
|
|
66
|
+
// dirname('/')==='/' so if we happen to reach the FS root (as might happen in a container we need to quit to avoid looping forever
|
|
67
|
+
if (parentDir === currentDir)
|
|
68
|
+
break;
|
|
69
|
+
const newLockFile = findRootLockFile(parentDir);
|
|
70
|
+
if (!newLockFile)
|
|
71
|
+
break;
|
|
72
|
+
lockFiles.push(newLockFile);
|
|
73
|
+
}
|
|
74
|
+
return (0, path_1.dirname)(lockFiles[lockFiles.length - 1]);
|
|
75
|
+
}
|
package/cjs/index.d.ts
CHANGED
|
@@ -8,6 +8,9 @@ declare const utoopack: {
|
|
|
8
8
|
serve: typeof serve;
|
|
9
9
|
};
|
|
10
10
|
export default utoopack;
|
|
11
|
+
export * from "./find-root";
|
|
12
|
+
export * from "./types";
|
|
13
|
+
export * from "./webpackCompat";
|
|
11
14
|
export type WebpackConfig = webpackCompat.WebpackConfig;
|
|
12
15
|
declare namespace utoopack {
|
|
13
16
|
type WebpackConfig = webpackCompat.WebpackConfig;
|
package/cjs/index.js
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
17
|
exports.serve = exports.build = void 0;
|
|
4
18
|
const build_1 = require("./build");
|
|
@@ -7,3 +21,6 @@ const dev_1 = require("./dev");
|
|
|
7
21
|
Object.defineProperty(exports, "serve", { enumerable: true, get: function () { return dev_1.serve; } });
|
|
8
22
|
const utoopack = { build: build_1.build, serve: dev_1.serve };
|
|
9
23
|
exports.default = utoopack;
|
|
24
|
+
__exportStar(require("./find-root"), exports);
|
|
25
|
+
__exportStar(require("./types"), exports);
|
|
26
|
+
__exportStar(require("./webpackCompat"), exports);
|
package/esm/build.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { nanoid } from "nanoid";
|
|
2
|
+
import { findRootDir } from "./find-root";
|
|
2
3
|
import { projectFactory } from "./project";
|
|
3
4
|
import { blockStdout, createDefineEnv, formatIssue, isRelevantWarning, } from "./util";
|
|
4
5
|
import { compatOptionsFromWebpack } from "./webpackCompat";
|
|
@@ -7,6 +8,10 @@ export function build(options, projectPath, rootPath) {
|
|
|
7
8
|
const bundleOptions = options.compatMode
|
|
8
9
|
? compatOptionsFromWebpack(options)
|
|
9
10
|
: options;
|
|
11
|
+
if (!rootPath) {
|
|
12
|
+
// help user to find the rootDir automatically.
|
|
13
|
+
rootPath = findRootDir(projectPath || process.cwd());
|
|
14
|
+
}
|
|
10
15
|
return buildInternal(bundleOptions, projectPath, rootPath);
|
|
11
16
|
}
|
|
12
17
|
async function buildInternal(bundleOptions, projectPath, rootPath) {
|
|
@@ -46,10 +51,10 @@ async function buildInternal(bundleOptions, projectPath, rootPath) {
|
|
|
46
51
|
}
|
|
47
52
|
}
|
|
48
53
|
if (topLevelWarnings.length > 0) {
|
|
49
|
-
console.warn(`
|
|
54
|
+
console.warn(`Utoopack build encountered ${topLevelWarnings.length} warnings:\n${topLevelWarnings.join("\n")}`);
|
|
50
55
|
}
|
|
51
56
|
if (topLevelErrors.length > 0) {
|
|
52
|
-
throw new Error(`
|
|
57
|
+
throw new Error(`Utoopack build failed with ${topLevelErrors.length} errors:\n${topLevelErrors.join("\n")}`);
|
|
53
58
|
}
|
|
54
59
|
await project.shutdown();
|
|
55
60
|
// TODO: Maybe run tasks in worker is a better way, see
|
package/esm/dev.js
CHANGED
|
@@ -5,6 +5,7 @@ import { isIPv6 } from "net";
|
|
|
5
5
|
import path from "path";
|
|
6
6
|
import send from "send";
|
|
7
7
|
import url from "url";
|
|
8
|
+
import { findRootDir } from "./find-root";
|
|
8
9
|
import { createHotReloader } from "./hmr";
|
|
9
10
|
import { createSelfSignedCertificate } from "./mkcert";
|
|
10
11
|
import { blockStdout } from "./util";
|
|
@@ -14,6 +15,10 @@ export function serve(options, projectPath, rootPath, serverOptions) {
|
|
|
14
15
|
const bundleOptions = options.compatMode
|
|
15
16
|
? compatOptionsFromWebpack(options)
|
|
16
17
|
: options;
|
|
18
|
+
if (!rootPath) {
|
|
19
|
+
// help user to find the rootDir automatically
|
|
20
|
+
rootPath = findRootDir(projectPath || process.cwd());
|
|
21
|
+
}
|
|
17
22
|
return serveInternal(bundleOptions, projectPath, rootPath, serverOptions);
|
|
18
23
|
}
|
|
19
24
|
async function serveInternal(options, projectPath, rootPath, serverOptions) {
|
|
@@ -21,7 +26,7 @@ async function serveInternal(options, projectPath, rootPath, serverOptions) {
|
|
|
21
26
|
if (process.env.XCODE_PROFILE) {
|
|
22
27
|
await xcodeProfilingReady();
|
|
23
28
|
}
|
|
24
|
-
startServer({
|
|
29
|
+
await startServer({
|
|
25
30
|
hostname: (serverOptions === null || serverOptions === void 0 ? void 0 : serverOptions.hostname) || "localhost",
|
|
26
31
|
port: (serverOptions === null || serverOptions === void 0 ? void 0 : serverOptions.port) || 3000,
|
|
27
32
|
https: serverOptions === null || serverOptions === void 0 ? void 0 : serverOptions.https,
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function findRootLockFile(cwd: string): string | undefined;
|
|
2
|
+
export declare function findPackageJson(cwd: string): string | undefined;
|
|
3
|
+
export declare function findWorkspacesRoot(cwd: string): string;
|
|
4
|
+
export declare function findRootDir(cwd: string): string;
|
package/esm/find-root.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import findUp from "find-up";
|
|
2
|
+
import { readFileSync } from "fs";
|
|
3
|
+
import { dirname } from "path";
|
|
4
|
+
export function findRootLockFile(cwd) {
|
|
5
|
+
return findUp.sync([
|
|
6
|
+
"pnpm-lock.yaml",
|
|
7
|
+
"package-lock.json",
|
|
8
|
+
"yarn.lock",
|
|
9
|
+
"bun.lock",
|
|
10
|
+
"bun.lockb",
|
|
11
|
+
], {
|
|
12
|
+
cwd,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
// compitable with tnpm
|
|
16
|
+
export function findPackageJson(cwd) {
|
|
17
|
+
return findUp.sync(["package.json"], {
|
|
18
|
+
cwd,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
function isWorkspaceRoot(pkgPath) {
|
|
22
|
+
const pkgJson = readFileSync(pkgPath, "utf-8");
|
|
23
|
+
const pkgJsonContent = JSON.parse(pkgJson);
|
|
24
|
+
return Boolean(pkgJsonContent.workspaces);
|
|
25
|
+
}
|
|
26
|
+
// refer from: https://github.com/umijs/mako/blob/next/crates/cli/src/helper/workspace.rs#L153
|
|
27
|
+
// TODO: 这块逻辑后续跟 utoo-pkg 使用一套方法
|
|
28
|
+
export function findWorkspacesRoot(cwd) {
|
|
29
|
+
const pkgJson = findPackageJson(cwd);
|
|
30
|
+
if (!pkgJson)
|
|
31
|
+
return cwd;
|
|
32
|
+
const pkgJsonFiles = [pkgJson];
|
|
33
|
+
while (true) {
|
|
34
|
+
const lastPkgJson = pkgJsonFiles[pkgJsonFiles.length - 1];
|
|
35
|
+
const currentDir = dirname(lastPkgJson);
|
|
36
|
+
const parentDir = dirname(currentDir);
|
|
37
|
+
if (parentDir === currentDir)
|
|
38
|
+
break;
|
|
39
|
+
if (isWorkspaceRoot(lastPkgJson))
|
|
40
|
+
break;
|
|
41
|
+
const newPkgJson = findPackageJson(parentDir);
|
|
42
|
+
if (!newPkgJson)
|
|
43
|
+
break;
|
|
44
|
+
pkgJsonFiles.push(newPkgJson);
|
|
45
|
+
}
|
|
46
|
+
return dirname(pkgJsonFiles[pkgJsonFiles.length - 1]);
|
|
47
|
+
}
|
|
48
|
+
export function findRootDir(cwd) {
|
|
49
|
+
const lockFile = findRootLockFile(cwd);
|
|
50
|
+
if (!lockFile)
|
|
51
|
+
return findWorkspacesRoot(cwd);
|
|
52
|
+
const lockFiles = [lockFile];
|
|
53
|
+
while (true) {
|
|
54
|
+
const lastLockFile = lockFiles[lockFiles.length - 1];
|
|
55
|
+
const currentDir = dirname(lastLockFile);
|
|
56
|
+
const parentDir = dirname(currentDir);
|
|
57
|
+
// dirname('/')==='/' so if we happen to reach the FS root (as might happen in a container we need to quit to avoid looping forever
|
|
58
|
+
if (parentDir === currentDir)
|
|
59
|
+
break;
|
|
60
|
+
const newLockFile = findRootLockFile(parentDir);
|
|
61
|
+
if (!newLockFile)
|
|
62
|
+
break;
|
|
63
|
+
lockFiles.push(newLockFile);
|
|
64
|
+
}
|
|
65
|
+
return dirname(lockFiles[lockFiles.length - 1]);
|
|
66
|
+
}
|
package/esm/index.d.ts
CHANGED
|
@@ -8,6 +8,9 @@ declare const utoopack: {
|
|
|
8
8
|
serve: typeof serve;
|
|
9
9
|
};
|
|
10
10
|
export default utoopack;
|
|
11
|
+
export * from "./find-root";
|
|
12
|
+
export * from "./types";
|
|
13
|
+
export * from "./webpackCompat";
|
|
11
14
|
export type WebpackConfig = webpackCompat.WebpackConfig;
|
|
12
15
|
declare namespace utoopack {
|
|
13
16
|
type WebpackConfig = webpackCompat.WebpackConfig;
|
package/esm/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@utoo/pack",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.41",
|
|
4
4
|
"main": "cjs/index.js",
|
|
5
5
|
"module": "esm/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"react-refresh": "^0.12.0",
|
|
42
42
|
"@babel/code-frame": "7.22.5",
|
|
43
43
|
"@swc/helpers": "0.5.15",
|
|
44
|
+
"find-up": "4.1.0",
|
|
44
45
|
"loader-runner": "^4.3.0",
|
|
45
46
|
"less": "^4.0.0",
|
|
46
47
|
"less-loader": "^12.0.0",
|
|
@@ -69,7 +70,7 @@
|
|
|
69
70
|
"@types/webpack": "^5.28.5"
|
|
70
71
|
},
|
|
71
72
|
"engines": {
|
|
72
|
-
"node": ">=
|
|
73
|
+
"node": ">= 20"
|
|
73
74
|
},
|
|
74
75
|
"scripts": {
|
|
75
76
|
"build:cjs": "rm -rf cjs && tsc -p ./tsconfig.json --module commonjs --outDir cjs && cp src/*.d.ts cjs/",
|
|
@@ -84,12 +85,12 @@
|
|
|
84
85
|
},
|
|
85
86
|
"repository": "git@github.com:umijs/mako.git",
|
|
86
87
|
"optionalDependencies": {
|
|
87
|
-
"@utoo/pack-darwin-arm64": "0.0.1-alpha.
|
|
88
|
-
"@utoo/pack-darwin-x64": "0.0.1-alpha.
|
|
89
|
-
"@utoo/pack-linux-arm64-gnu": "0.0.1-alpha.
|
|
90
|
-
"@utoo/pack-linux-arm64-musl": "0.0.1-alpha.
|
|
91
|
-
"@utoo/pack-linux-x64-gnu": "0.0.1-alpha.
|
|
92
|
-
"@utoo/pack-linux-x64-musl": "0.0.1-alpha.
|
|
93
|
-
"@utoo/pack-win32-x64-msvc": "0.0.1-alpha.
|
|
88
|
+
"@utoo/pack-darwin-arm64": "0.0.1-alpha.41",
|
|
89
|
+
"@utoo/pack-darwin-x64": "0.0.1-alpha.41",
|
|
90
|
+
"@utoo/pack-linux-arm64-gnu": "0.0.1-alpha.41",
|
|
91
|
+
"@utoo/pack-linux-arm64-musl": "0.0.1-alpha.41",
|
|
92
|
+
"@utoo/pack-linux-x64-gnu": "0.0.1-alpha.41",
|
|
93
|
+
"@utoo/pack-linux-x64-musl": "0.0.1-alpha.41",
|
|
94
|
+
"@utoo/pack-win32-x64-msvc": "0.0.1-alpha.41"
|
|
94
95
|
}
|
|
95
96
|
}
|