auklet 0.1.4 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +116 -429
- package/dist/cli/build.d.ts +3 -5
- package/dist/cli/build.js +86 -23
- package/dist/cli/buildCss.d.ts +10 -5
- package/dist/cli/buildCss.js +21 -17
- package/dist/cli/buildWorkspace.d.ts +24 -0
- package/dist/cli/buildWorkspace.js +43 -0
- package/dist/cli/dev.d.ts +2 -1
- package/dist/cli/dev.js +130 -23
- package/dist/cli/main.js +167 -26
- package/dist/cli/parse/build.d.ts +63 -0
- package/dist/cli/{buildArgs.js → parse/build.js} +47 -22
- package/dist/cli/parse/core.d.ts +14 -0
- package/dist/cli/parse/core.js +68 -0
- package/dist/cli/parse/dev.d.ts +18 -0
- package/dist/cli/parse/dev.js +4 -0
- package/dist/cli/parse/owner.d.ts +11 -0
- package/dist/cli/parse/owner.js +25 -0
- package/dist/cli/parse/publish.d.ts +19 -0
- package/dist/cli/parse/publish.js +60 -0
- package/dist/cli/parse/workspace.d.ts +14 -0
- package/dist/cli/parse/workspace.js +60 -0
- package/dist/css/inspect.js +4 -3
- package/dist/publish/api/pnpmApi.d.ts +0 -4
- package/dist/publish/api/pnpmApi.js +0 -34
- package/dist/publish/cli.d.ts +0 -16
- package/dist/publish/cli.js +5 -122
- package/dist/publish/inspect.js +2 -2
- package/dist/publish/targetResolver.js +28 -72
- package/dist/publish/types.d.ts +1 -7
- package/dist/workspace/targets.d.ts +31 -0
- package/dist/workspace/targets.js +144 -0
- package/package.json +1 -1
- package/dist/cli/buildArgs.d.ts +0 -9
- package/dist/cli/publish.d.ts +0 -2
- package/dist/cli/publish.js +0 -9
- /package/dist/cli/{values.d.ts → parse/values.d.ts} +0 -0
- /package/dist/cli/{values.js → parse/values.js} +0 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { isPlainObject } from 'aidly';
|
|
3
|
+
import { findWorkspaceRoot } from '#auklet/workspace/root';
|
|
4
|
+
import { readPnpmWorkspacePackageInfo } from '#auklet/workspace/packages';
|
|
5
|
+
export async function resolveWorkspacePackageInfos(cwd, filters, options) {
|
|
6
|
+
const root = requireWorkspaceRoot(cwd, options.scope);
|
|
7
|
+
const packages = await readWorkspacePackageInfo(root, options);
|
|
8
|
+
return filterWorkspacePackages(packages, filters, options.scope);
|
|
9
|
+
}
|
|
10
|
+
export async function resolveWorkspaceTargets(options) {
|
|
11
|
+
const root = requireWorkspaceRoot(options.cwd, options.scope);
|
|
12
|
+
const packages = filterWorkspaceRootPackage(await readWorkspacePackageInfo(root, options), root, options);
|
|
13
|
+
const matchedPackages = filterWorkspacePackages(packages, options.filters, options.scope);
|
|
14
|
+
const targetFactory = createWorkspaceTargetFactory(options);
|
|
15
|
+
const targets = options.includeDependencies
|
|
16
|
+
? includeWorkspaceDependencies(matchedPackages, packages, targetFactory, options)
|
|
17
|
+
: matchedPackages
|
|
18
|
+
.map((item) => targetFactory.create(item))
|
|
19
|
+
.filter(isWorkspaceTarget);
|
|
20
|
+
if (!targets.length) {
|
|
21
|
+
throw new Error(options.emptyTargetMessage);
|
|
22
|
+
}
|
|
23
|
+
return sortWorkspaceTargets(targets, {
|
|
24
|
+
getDependencies: options.getDependencies,
|
|
25
|
+
scope: options.scope,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
export function getWorkspaceDependencyNames(value) {
|
|
29
|
+
return isPlainObject(value) ? Object.keys(value) : [];
|
|
30
|
+
}
|
|
31
|
+
const filterWorkspaceRootPackage = (packages, root, options) => {
|
|
32
|
+
if (!options.excludeRoot)
|
|
33
|
+
return packages;
|
|
34
|
+
const normalizedRoot = path.resolve(root);
|
|
35
|
+
return packages.filter((item) => path.resolve(item.path) !== normalizedRoot);
|
|
36
|
+
};
|
|
37
|
+
const isWorkspaceTarget = (target) => {
|
|
38
|
+
return target !== null;
|
|
39
|
+
};
|
|
40
|
+
const createWorkspaceTargetFactory = (options) => {
|
|
41
|
+
const cache = new Map();
|
|
42
|
+
const create = (item) => {
|
|
43
|
+
const cached = cache.get(item.name);
|
|
44
|
+
if (cached !== undefined)
|
|
45
|
+
return cached;
|
|
46
|
+
if (!options.includePrivate && item.private) {
|
|
47
|
+
options.onPrivatePackage?.(item, {
|
|
48
|
+
exact: options.filters.includes(item.name),
|
|
49
|
+
});
|
|
50
|
+
cache.set(item.name, null);
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
const packageJson = options.readPackageJson(item.path);
|
|
54
|
+
const target = options.createTarget(item, packageJson);
|
|
55
|
+
cache.set(item.name, target);
|
|
56
|
+
return target;
|
|
57
|
+
};
|
|
58
|
+
return { create };
|
|
59
|
+
};
|
|
60
|
+
const includeWorkspaceDependencies = (matchedPackages, packages, targetFactory, options) => {
|
|
61
|
+
const packageMap = new Map(packages.map((item) => [item.name, item]));
|
|
62
|
+
const included = new Map();
|
|
63
|
+
const include = (item) => {
|
|
64
|
+
const target = targetFactory.create(item);
|
|
65
|
+
if (!target || included.has(target.packageName))
|
|
66
|
+
return;
|
|
67
|
+
included.set(target.packageName, target);
|
|
68
|
+
for (const dependency of options.getDependencies(target)) {
|
|
69
|
+
const dependencyItem = packageMap.get(dependency);
|
|
70
|
+
if (dependencyItem)
|
|
71
|
+
include(dependencyItem);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
for (const item of matchedPackages) {
|
|
75
|
+
include(item);
|
|
76
|
+
}
|
|
77
|
+
return [...included.values()];
|
|
78
|
+
};
|
|
79
|
+
const requireWorkspaceRoot = (cwd, scope) => {
|
|
80
|
+
const root = findWorkspaceRoot(cwd);
|
|
81
|
+
if (!root) {
|
|
82
|
+
throw new Error(`[${scope}] --filter requires a pnpm workspace root.`);
|
|
83
|
+
}
|
|
84
|
+
return root;
|
|
85
|
+
};
|
|
86
|
+
const readWorkspacePackageInfo = async (root, options) => {
|
|
87
|
+
try {
|
|
88
|
+
return await readPnpmWorkspacePackageInfo(root, {
|
|
89
|
+
env: options.env,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
if (!options.readErrorMessage)
|
|
94
|
+
throw error;
|
|
95
|
+
throw new Error(options.readErrorMessage, {
|
|
96
|
+
cause: error,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
const filterWorkspacePackages = (packages, filters, scope) => {
|
|
101
|
+
const matched = packages.filter((item) => filters.some((filter) => matchesWorkspacePackageFilter(item.name, filter)));
|
|
102
|
+
if (!matched.length) {
|
|
103
|
+
throw new Error(`[${scope}] no workspace package matched filter: ${filters.join(', ')}`);
|
|
104
|
+
}
|
|
105
|
+
return matched;
|
|
106
|
+
};
|
|
107
|
+
const matchesWorkspacePackageFilter = (packageName, filter) => {
|
|
108
|
+
if (filter === '*')
|
|
109
|
+
return true;
|
|
110
|
+
if (filter.endsWith('/*')) {
|
|
111
|
+
const scope = filter.slice(0, -2);
|
|
112
|
+
return packageName.startsWith(`${scope}/`);
|
|
113
|
+
}
|
|
114
|
+
return packageName === filter;
|
|
115
|
+
};
|
|
116
|
+
const sortWorkspaceTargets = (targets, options) => {
|
|
117
|
+
const targetNames = new Set(targets.map((target) => target.packageName));
|
|
118
|
+
const targetMap = new Map(targets.map((target) => [target.packageName, target]));
|
|
119
|
+
const sorted = [];
|
|
120
|
+
const visited = new Set();
|
|
121
|
+
const visiting = new Set();
|
|
122
|
+
const visit = (target) => {
|
|
123
|
+
if (visited.has(target.packageName))
|
|
124
|
+
return;
|
|
125
|
+
if (visiting.has(target.packageName)) {
|
|
126
|
+
throw new Error(`[${options.scope}] circular workspace dependency detected at ${target.packageName}.`);
|
|
127
|
+
}
|
|
128
|
+
visiting.add(target.packageName);
|
|
129
|
+
for (const dependency of options.getDependencies(target)) {
|
|
130
|
+
if (!targetNames.has(dependency))
|
|
131
|
+
continue;
|
|
132
|
+
const dependencyTarget = targetMap.get(dependency);
|
|
133
|
+
if (dependencyTarget)
|
|
134
|
+
visit(dependencyTarget);
|
|
135
|
+
}
|
|
136
|
+
visiting.delete(target.packageName);
|
|
137
|
+
visited.add(target.packageName);
|
|
138
|
+
sorted.push(target);
|
|
139
|
+
};
|
|
140
|
+
for (const target of targets) {
|
|
141
|
+
visit(target);
|
|
142
|
+
}
|
|
143
|
+
return sorted;
|
|
144
|
+
};
|
package/package.json
CHANGED
package/dist/cli/buildArgs.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { AukletEnvContext } from '#auklet/env';
|
|
2
|
-
import type { AukletConfig } from '#auklet/types';
|
|
3
|
-
export declare function resolveBuildCliArgs(args: Array<string>, envContext?: AukletEnvContext): {
|
|
4
|
-
args: string[];
|
|
5
|
-
config: AukletConfig;
|
|
6
|
-
};
|
|
7
|
-
export declare function createBuildEnv(config: AukletConfig): {
|
|
8
|
-
AUKLET_CONFIG_OVERRIDES: string;
|
|
9
|
-
} | undefined;
|
package/dist/cli/publish.d.ts
DELETED
package/dist/cli/publish.js
DELETED
|
File without changes
|
|
File without changes
|