@driveflux/fab 1.0.9 → 2.0.0-next.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/.turbo/turbo-build.log +13 -16
- package/CHANGELOG.md +1 -80
- package/bin/fab.js +6 -7
- package/dist/build.d.ts +5 -7
- package/dist/build.d.ts.map +1 -1
- package/dist/build.js +79 -166
- package/dist/clean.d.ts.map +1 -1
- package/dist/clean.js +17 -17
- package/dist/config.d.ts +0 -8
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +11 -13
- package/dist/create.d.ts.map +1 -1
- package/dist/create.js +8 -8
- package/dist/index.js +5 -5
- package/dist/utils.d.ts +2 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +21 -22
- package/package.json +11 -14
- package/src/build.ts +73 -119
- package/src/clean.ts +4 -8
- package/src/config.ts +12 -18
- package/src/create.ts +9 -17
- package/src/types.ts +1 -1
- package/src/utils.ts +6 -6
- package/templates/backend/package.json +1 -1
- package/templates/backend/src/index.ts +0 -1
- package/templates/frontend/package.json +1 -1
- package/templates/frontend/src/index.ts +0 -1
- package/tsconfig.tsbuildinfo +1 -1
package/dist/config.js
CHANGED
|
@@ -122,13 +122,11 @@ function _ts_generator(thisArg, body) {
|
|
|
122
122
|
};
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
|
-
import fs from
|
|
126
|
-
import path from
|
|
127
|
-
import { z } from
|
|
125
|
+
import fs from "node:fs/promises";
|
|
126
|
+
import path from "node:path";
|
|
127
|
+
import { z } from "zod";
|
|
128
128
|
var ConfigValidation = z.object({
|
|
129
|
-
doNotCleanup: z.array(z.string())
|
|
130
|
-
noCJS: z.boolean().optional(),
|
|
131
|
-
copyVerbatim: z.array(z.string())
|
|
129
|
+
doNotCleanup: z.array(z.string())
|
|
132
130
|
}).partial();
|
|
133
131
|
export var parseConfig = function() {
|
|
134
132
|
var _ref = _async_to_generator(function(options) {
|
|
@@ -203,11 +201,11 @@ var findConfigFile = function() {
|
|
|
203
201
|
files = _state.sent();
|
|
204
202
|
configFile = files.find(function(f) {
|
|
205
203
|
return [
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
204
|
+
"fab.config.js",
|
|
205
|
+
"fab.config.cjs",
|
|
206
|
+
"fab.config.mjs",
|
|
207
|
+
"fabrc.json",
|
|
208
|
+
".fabrc"
|
|
211
209
|
].includes(f);
|
|
212
210
|
});
|
|
213
211
|
_tmp = configFile;
|
|
@@ -254,14 +252,14 @@ var readConfigFile = function() {
|
|
|
254
252
|
_state.sent().default
|
|
255
253
|
];
|
|
256
254
|
case 2:
|
|
257
|
-
if (!(configPath.endsWith(
|
|
255
|
+
if (!(configPath.endsWith(".json") || configPath.split("/").pop() === ".fabrc")) return [
|
|
258
256
|
3,
|
|
259
257
|
4
|
|
260
258
|
];
|
|
261
259
|
_ = JSON.parse;
|
|
262
260
|
return [
|
|
263
261
|
4,
|
|
264
|
-
fs.readFile(configPath,
|
|
262
|
+
fs.readFile(configPath, "utf-8")
|
|
265
263
|
];
|
|
266
264
|
case 3:
|
|
267
265
|
return [
|
package/dist/create.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AAIA,UAAU,aAAa;IACrB,QAAQ,EAAE,SAAS,GAAG,UAAU,CAAA;IAChC,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,kBAAkB,CAAC,EAAE,OAAO,CAAA;CAC7B;AAED,eAAO,MAAM,MAAM,+
|
|
1
|
+
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AAIA,UAAU,aAAa;IACrB,QAAQ,EAAE,SAAS,GAAG,UAAU,CAAA;IAChC,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,kBAAkB,CAAC,EAAE,OAAO,CAAA;CAC7B;AAED,eAAO,MAAM,MAAM,+FAAsG,aAAa,kBAqCrI,CAAA"}
|
package/dist/create.js
CHANGED
|
@@ -122,10 +122,10 @@ function _ts_generator(thisArg, body) {
|
|
|
122
122
|
};
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
|
-
import { deleteAsync } from
|
|
126
|
-
import fs from
|
|
127
|
-
import path from
|
|
128
|
-
import { ensureDir, getBaseDir, runCommand } from
|
|
125
|
+
import { deleteAsync } from "del";
|
|
126
|
+
import fs from "node:fs/promises";
|
|
127
|
+
import path from "node:path";
|
|
128
|
+
import { ensureDir, getBaseDir, runCommand } from "./utils.js";
|
|
129
129
|
export var create = function() {
|
|
130
130
|
var _ref = _async_to_generator(function(param) {
|
|
131
131
|
var template, name, providedDestination, providedCwd, dangerouslyRewrite, cwd, destination, finalDestination, e, templatePath;
|
|
@@ -220,8 +220,8 @@ export var create = function() {
|
|
|
220
220
|
_state.sent();
|
|
221
221
|
return [
|
|
222
222
|
4,
|
|
223
|
-
runCommand(
|
|
224
|
-
|
|
223
|
+
runCommand("pnpm", [
|
|
224
|
+
"i"
|
|
225
225
|
], {
|
|
226
226
|
cwd: cwd
|
|
227
227
|
})
|
|
@@ -246,12 +246,12 @@ var replaceInFile = function() {
|
|
|
246
246
|
case 0:
|
|
247
247
|
return [
|
|
248
248
|
4,
|
|
249
|
-
fs.readFile(filePath,
|
|
249
|
+
fs.readFile(filePath, "utf-8")
|
|
250
250
|
];
|
|
251
251
|
case 1:
|
|
252
252
|
content = _state.sent();
|
|
253
253
|
// No time to build the regex and replace logic, that's for later, we just replace the name now
|
|
254
|
-
newContent = content.replace(
|
|
254
|
+
newContent = content.replace("{{name}}", replacements.name);
|
|
255
255
|
return [
|
|
256
256
|
4,
|
|
257
257
|
fs.writeFile(filePath, newContent)
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
1
|
+
export * from "./build.js";
|
|
2
|
+
export * from "./clean.js";
|
|
3
|
+
export * from "./config.js";
|
|
4
|
+
export * from "./create.js";
|
|
5
|
+
export * from "./types.js";
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
1
2
|
import { SpawnOptions } from 'node:child_process';
|
|
2
3
|
import { Config } from './config.js';
|
|
3
4
|
import { BaseOptions } from './types.js';
|
|
@@ -13,6 +14,6 @@ export declare const ensureDir: (dir: string) => Promise<void>;
|
|
|
13
14
|
export declare const runCommand: (cmd: string, args: string[], options: SpawnOptions) => Promise<unknown>;
|
|
14
15
|
export declare const validatePackageJson: ({ command, cwd: providedCwd }: ValidatePackageOptions) => Promise<void>;
|
|
15
16
|
export declare const getBaseDir: () => string;
|
|
16
|
-
export declare const getDefaultOptions: () => Required<BaseOptions
|
|
17
|
+
export declare const getDefaultOptions: () => Required<BaseOptions & Config>;
|
|
17
18
|
export {};
|
|
18
19
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAS,MAAM,oBAAoB,CAAA;AAGxD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAExC,UAAU,sBAAuB,SAAQ,WAAW;IAClD,OAAO,EAAE,MAAM,OAAO,aAAa,CAAA;CACpC;AAED,QAAA,MAAM,aAAa;;;;CAIT,CAAA;AAEV,eAAO,MAAM,SAAS,QAAe,MAAM,kBAS1C,CAAA;AAED,eAAO,MAAM,UAAU,QAAe,MAAM,QAAQ,MAAM,EAAE,WAAW,YAAY,qBAelF,CAAA;AAED,eAAO,MAAM,mBAAmB,kCAAyC,sBAAsB,kBA2B9F,CAAA;AAED,eAAO,MAAM,UAAU,cAGtB,CAAA;AAED,eAAO,MAAM,iBAAiB,QAAO,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAS,MAAM,oBAAoB,CAAA;AAGxD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAExC,UAAU,sBAAuB,SAAQ,WAAW;IAClD,OAAO,EAAE,MAAM,OAAO,aAAa,CAAA;CACpC;AAED,QAAA,MAAM,aAAa;;;;CAIT,CAAA;AAEV,eAAO,MAAM,SAAS,QAAe,MAAM,kBAS1C,CAAA;AAED,eAAO,MAAM,UAAU,QAAe,MAAM,QAAQ,MAAM,EAAE,WAAW,YAAY,qBAelF,CAAA;AAED,eAAO,MAAM,mBAAmB,kCAAyC,sBAAsB,kBA2B9F,CAAA;AAED,eAAO,MAAM,UAAU,cAGtB,CAAA;AAED,eAAO,MAAM,iBAAiB,QAAO,SAAS,WAAW,GAAG,MAAM,CAKrD,CAAA"}
|
package/dist/utils.js
CHANGED
|
@@ -150,19 +150,19 @@ function _ts_generator(thisArg, body) {
|
|
|
150
150
|
};
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
|
-
import { spawn } from
|
|
154
|
-
import fs from
|
|
155
|
-
import path from
|
|
153
|
+
import { spawn } from "node:child_process";
|
|
154
|
+
import fs from "node:fs/promises";
|
|
155
|
+
import path from "node:path";
|
|
156
156
|
var REQUIRED_DEPS = {
|
|
157
157
|
del: [
|
|
158
|
-
|
|
158
|
+
"del-cli"
|
|
159
159
|
],
|
|
160
160
|
tsc: [
|
|
161
|
-
|
|
161
|
+
"typescript"
|
|
162
162
|
],
|
|
163
163
|
swc: [
|
|
164
|
-
|
|
165
|
-
|
|
164
|
+
"@swc/core",
|
|
165
|
+
"@swc/cli"
|
|
166
166
|
]
|
|
167
167
|
};
|
|
168
168
|
export var ensureDir = function() {
|
|
@@ -220,16 +220,16 @@ export var runCommand = function() {
|
|
|
220
220
|
var c;
|
|
221
221
|
return _ts_generator(this, function(_state) {
|
|
222
222
|
c = spawn(cmd, args, _object_spread({
|
|
223
|
-
stdio:
|
|
223
|
+
stdio: "inherit"
|
|
224
224
|
}, options));
|
|
225
225
|
return [
|
|
226
226
|
2,
|
|
227
227
|
new Promise(function(resolve, reject) {
|
|
228
|
-
c.on(
|
|
228
|
+
c.on("error", function(error) {
|
|
229
229
|
console.error(error);
|
|
230
230
|
reject(error);
|
|
231
231
|
});
|
|
232
|
-
c.on(
|
|
232
|
+
c.on("close", function(code) {
|
|
233
233
|
if (code !== 0) {
|
|
234
234
|
reject(new Error("Command exited with code ".concat(code)));
|
|
235
235
|
} else {
|
|
@@ -255,17 +255,17 @@ export var validatePackageJson = function() {
|
|
|
255
255
|
_ = JSON.parse;
|
|
256
256
|
return [
|
|
257
257
|
4,
|
|
258
|
-
fs.readFile(path.join(cwd,
|
|
258
|
+
fs.readFile(path.join(cwd, "package.json"), "utf-8")
|
|
259
259
|
];
|
|
260
260
|
case 1:
|
|
261
261
|
pkg = _.apply(JSON, [
|
|
262
262
|
_state.sent()
|
|
263
263
|
]);
|
|
264
|
-
packageName = cwd.split(
|
|
264
|
+
packageName = cwd.split("/").pop();
|
|
265
265
|
notAllowedInScripts = [
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
266
|
+
"del",
|
|
267
|
+
"tsc",
|
|
268
|
+
"swc"
|
|
269
269
|
];
|
|
270
270
|
if (command in pkg.scripts && notAllowedInScripts.includes(command)) {
|
|
271
271
|
console.log("\uD83D\uDEA8 The ".concat(command, " script is not allowed. Remove the ").concat(command, " script from ").concat(packageName, "/package.json"));
|
|
@@ -279,7 +279,7 @@ export var validatePackageJson = function() {
|
|
|
279
279
|
return !(d in allDeps);
|
|
280
280
|
});
|
|
281
281
|
if (missingDeps.length > 0) {
|
|
282
|
-
console.log("\uD83D\uDEA8 The ".concat(command, " script requires the following dependencies: ").concat(missingDeps.join(
|
|
282
|
+
console.log("\uD83D\uDEA8 The ".concat(command, " script requires the following dependencies: ").concat(missingDeps.join(", "), ". Add them to ").concat(packageName, "/package.json"));
|
|
283
283
|
process.exit(1);
|
|
284
284
|
}
|
|
285
285
|
return [
|
|
@@ -294,16 +294,15 @@ export var validatePackageJson = function() {
|
|
|
294
294
|
}();
|
|
295
295
|
export var getBaseDir = function() {
|
|
296
296
|
// This file will end up in ./dist, so we need to remove the dist from the path
|
|
297
|
-
return path.resolve(path.dirname(decodeURIComponent(new URL(import.meta.url).pathname)),
|
|
297
|
+
return path.resolve(path.dirname(decodeURIComponent(new URL(import.meta.url).pathname)), "..");
|
|
298
298
|
};
|
|
299
299
|
export var getDefaultOptions = function() {
|
|
300
300
|
return {
|
|
301
301
|
cwd: process.cwd(),
|
|
302
|
-
destination:
|
|
302
|
+
destination: "dist",
|
|
303
303
|
doNotCleanup: [
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
]
|
|
307
|
-
noCJS: false
|
|
304
|
+
"src",
|
|
305
|
+
"bin"
|
|
306
|
+
]
|
|
308
307
|
};
|
|
309
308
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@driveflux/fab",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-next.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"bin": {
|
|
@@ -13,27 +13,24 @@
|
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"commander": "^
|
|
17
|
-
"fast-glob": "^3.3.2"
|
|
18
|
-
"lodash.merge": "^4.6.2"
|
|
16
|
+
"commander": "^11.1.0",
|
|
17
|
+
"fast-glob": "^3.3.2"
|
|
19
18
|
},
|
|
20
19
|
"devDependencies": {
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"@swc/
|
|
24
|
-
"@types/lodash.merge": "^4.6.9",
|
|
20
|
+
"zod": "^3.22.4",
|
|
21
|
+
"type-fest": "^4.8.2",
|
|
22
|
+
"@swc/cli": "^0.1.63",
|
|
25
23
|
"del": "^7.1.0",
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"zod": "^3.23.8"
|
|
24
|
+
"@swc/core": "^1.3.99",
|
|
25
|
+
"@swc-node/register": "^1.6.8",
|
|
26
|
+
"del-cli": "^5.1.0"
|
|
30
27
|
},
|
|
31
28
|
"peerDependencies": {
|
|
32
|
-
"typescript": "^5.
|
|
29
|
+
"typescript": "^5.3.3"
|
|
33
30
|
},
|
|
34
31
|
"scripts": {
|
|
35
32
|
"build": "pnpm build:js && pnpm build:types",
|
|
36
|
-
"build:js": "swc src
|
|
33
|
+
"build:js": "swc src -d dist",
|
|
37
34
|
"build:types": "tsc --build --emitDeclarationOnly",
|
|
38
35
|
"clean": "del dist/**/*.js",
|
|
39
36
|
"clean:all": "del dist/**/* tsconfig.tsbuildinfo",
|
package/src/build.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import fg from 'fast-glob'
|
|
2
|
-
import merge from 'lodash.merge'
|
|
3
2
|
import assert from 'node:assert'
|
|
4
3
|
import fs from 'node:fs/promises'
|
|
5
4
|
import path from 'node:path'
|
|
@@ -14,7 +13,6 @@ interface BuildOptions extends BaseOptions, MakeBaseExportsOptions, CleanOptions
|
|
|
14
13
|
noTypes?: boolean
|
|
15
14
|
noCJS?: boolean
|
|
16
15
|
noESM?: boolean
|
|
17
|
-
copyVerbatim?: string[]
|
|
18
16
|
}
|
|
19
17
|
|
|
20
18
|
interface MakeBaseExportsOptions extends BaseOptions {
|
|
@@ -33,8 +31,7 @@ interface ProcessEntryOptions extends BaseOptions {
|
|
|
33
31
|
noCJS?: boolean
|
|
34
32
|
}
|
|
35
33
|
|
|
36
|
-
export const build = async (
|
|
37
|
-
const options = merge({}, getDefaultOptions(), rawOptions)
|
|
34
|
+
export const build = async (options: BuildOptions = getDefaultOptions()) => {
|
|
38
35
|
// Cleanup first
|
|
39
36
|
await clean(options)
|
|
40
37
|
|
|
@@ -51,51 +48,25 @@ export const build = async (rawOptions?: BuildOptions) => {
|
|
|
51
48
|
promises.push(buildCjs(options))
|
|
52
49
|
}
|
|
53
50
|
|
|
54
|
-
promises.push(copyVerbatim(options))
|
|
55
|
-
|
|
56
51
|
// Build necessary files
|
|
57
52
|
await Promise.all(promises)
|
|
58
53
|
|
|
59
54
|
// Make exports for CJS
|
|
60
|
-
|
|
61
|
-
await makeBaseExports(options)
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export const copyVerbatim = async (rawOptions?: BuildOptions) => {
|
|
66
|
-
const options = merge({}, getDefaultOptions(), rawOptions)
|
|
67
|
-
if (options.copyVerbatim?.length) {
|
|
68
|
-
const cwd = options.cwd ?? process.cwd()
|
|
69
|
-
const destination = options.destination ?? getDefaultOptions().destination
|
|
70
|
-
await Promise.all(
|
|
71
|
-
options.copyVerbatim.map(async (fileOrFolderRaw) => {
|
|
72
|
-
const fileOrFolder = `src/${fileOrFolderRaw.replace(/^(\/)*src/, '')}`
|
|
73
|
-
const targetPath = path.resolve(destination, fileOrFolder).replace('/src', '')
|
|
74
|
-
const targetPathCjs = path.resolve(destination, 'cjs', fileOrFolder).replace('/src', '')
|
|
75
|
-
await ensureDir(path.dirname(targetPath))
|
|
76
|
-
await fs.cp(path.resolve(cwd, fileOrFolder), targetPath, { recursive: true })
|
|
77
|
-
await fs.cp(path.resolve(cwd, fileOrFolder), targetPathCjs, { recursive: true })
|
|
78
|
-
})
|
|
79
|
-
)
|
|
80
|
-
}
|
|
55
|
+
await makeBaseExports(options)
|
|
81
56
|
}
|
|
82
57
|
|
|
83
|
-
export const buildTypes = async (
|
|
84
|
-
const options = merge({}, getDefaultOptions(), rawOptions)
|
|
58
|
+
export const buildTypes = async (options: BaseOptions = getDefaultOptions()) => {
|
|
85
59
|
await validatePackageJson({ command: 'tsc', cwd: options.cwd })
|
|
86
60
|
await runCommand('pnpm', ['tsc', '--emitDeclarationOnly', '--declarationMap'], { cwd: options.cwd })
|
|
87
61
|
}
|
|
88
62
|
|
|
89
|
-
export const buildCjs = async (
|
|
90
|
-
const options = merge({}, getDefaultOptions(), rawOptions)
|
|
63
|
+
export const buildCjs = async (options: BaseOptions = getDefaultOptions()) => {
|
|
91
64
|
const cwd = options.cwd ?? process.cwd()
|
|
92
65
|
const destination = options.destination ?? getDefaultOptions().destination
|
|
93
66
|
const cjsPath = path.resolve(destination, 'cjs')
|
|
94
67
|
await validatePackageJson({ command: 'swc', cwd })
|
|
95
68
|
// We start by emitting the CJS files
|
|
96
|
-
await runCommand(`pnpm`, ['swc', 'src', '-C', 'module.type=commonjs', '
|
|
97
|
-
cwd
|
|
98
|
-
})
|
|
69
|
+
await runCommand(`pnpm`, ['swc', 'src', '-C', 'module.type=commonjs', '-d', cjsPath], { cwd })
|
|
99
70
|
const targetPath = path.resolve(cwd, cjsPath, 'package.json')
|
|
100
71
|
await ensureDir(path.dirname(targetPath))
|
|
101
72
|
await fs.writeFile(
|
|
@@ -106,8 +77,7 @@ export const buildCjs = async (rawOptions?: BaseOptions) => {
|
|
|
106
77
|
)
|
|
107
78
|
}
|
|
108
79
|
|
|
109
|
-
export const makeBaseExports = async (
|
|
110
|
-
const options = merge({}, getDefaultOptions(), rawOptions)
|
|
80
|
+
export const makeBaseExports = async (options: MakeBaseExportsOptions = getDefaultOptions()) => {
|
|
111
81
|
const cwd = options.cwd ?? process.cwd()
|
|
112
82
|
// Now, we need to read the exports from the package.json and create the cjs references
|
|
113
83
|
const exp = options.exports || (await parseExports(cwd))
|
|
@@ -190,78 +160,75 @@ const extractBaseExportsFromEntry = async (
|
|
|
190
160
|
throw new Error(`Only strings are allowed in the "${exportTypeKey}" field`)
|
|
191
161
|
}
|
|
192
162
|
|
|
193
|
-
const asteriskPosition = exportKeyValue
|
|
194
|
-
.replace('./', '')
|
|
195
|
-
.split('/')
|
|
196
|
-
.findIndex((p) => p.startsWith('*'))
|
|
163
|
+
const asteriskPosition = exportKeyValue.replace('./', '').split('/').findIndex((p) => p.startsWith('*'))
|
|
197
164
|
const paths = await parseExportPath(exportKeyValue, cwd)
|
|
198
165
|
|
|
199
|
-
const targetFiles = Promise.all(
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
}
|
|
166
|
+
const targetFiles = Promise.all(paths.map(async (p) => {
|
|
167
|
+
let finalKey = key
|
|
168
|
+
if (hasWildcard) {
|
|
169
|
+
finalKey = key.replace(
|
|
170
|
+
'*',
|
|
171
|
+
p
|
|
172
|
+
.split('/')
|
|
173
|
+
.slice(asteriskPosition, asteriskPosition + 1)
|
|
174
|
+
.join('/')
|
|
175
|
+
)
|
|
176
|
+
}
|
|
211
177
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
178
|
+
if (finalKey === '.' || finalKey === './') {
|
|
179
|
+
finalKey = 'index'
|
|
180
|
+
}
|
|
215
181
|
|
|
216
|
-
|
|
217
|
-
|
|
182
|
+
let content = ''
|
|
183
|
+
let targetFile: string = ''
|
|
218
184
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
185
|
+
const geImportPaths = (importPath: string) => {
|
|
186
|
+
const targetFile = path.resolve(cwd, importPath)
|
|
187
|
+
const importFromPath = path.dirname(targetFile)
|
|
188
|
+
const fullImportPath = path.resolve(cwd, p)
|
|
189
|
+
const relativeImportPath = path.relative(importFromPath, fullImportPath)
|
|
190
|
+
return { relativeImportPath, fullImportPath, targetFile }
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
if (type === 'cjs') {
|
|
195
|
+
finalKey = await resolvePathWithExtension(finalKey, 'cjs')
|
|
196
|
+
const importPaths = geImportPaths(finalKey)
|
|
197
|
+
const relativeImportPath = importPaths.relativeImportPath
|
|
198
|
+
targetFile = importPaths.targetFile
|
|
199
|
+
content = `module.exports = require('${formatImportPath(relativeImportPath)}')`
|
|
200
|
+
}
|
|
226
201
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
202
|
+
if (type === 'types') {
|
|
203
|
+
finalKey = await resolvePathWithExtension(finalKey, 'd.ts')
|
|
204
|
+
const importPaths = geImportPaths(finalKey)
|
|
205
|
+
const relativeImportPath = importPaths.relativeImportPath
|
|
206
|
+
targetFile = importPaths.targetFile
|
|
207
|
+
// Typescript will complain about exprting .d.ts, so we just omt that
|
|
208
|
+
content = `export * from '${formatImportPath(relativeImportPath).replace('.d.ts', '')}'`
|
|
209
|
+
|
|
210
|
+
// Now, let's go inside that file and see if it exports "default" and add that into the content
|
|
211
|
+
const fileContent = await fs.readFile(importPaths.fullImportPath, 'utf-8')
|
|
212
|
+
if (/export default/.test(fileContent)) {
|
|
213
|
+
content += `\nexport { default } from '${formatImportPath(relativeImportPath)}'`
|
|
233
214
|
}
|
|
215
|
+
}
|
|
234
216
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
const relativeImportPath = importPaths.relativeImportPath
|
|
239
|
-
targetFile = importPaths.targetFile
|
|
240
|
-
// Typescript will complain about exprting .d.ts, so we just omt that
|
|
241
|
-
content = `export * from '${formatImportPath(relativeImportPath).replace('.d.ts', '')}'`
|
|
242
|
-
|
|
243
|
-
// Now, let's go inside that file and see if it exports "default" and add that into the content
|
|
244
|
-
const fileContent = await fs.readFile(importPaths.fullImportPath, 'utf-8')
|
|
245
|
-
if (/export default/.test(fileContent)) {
|
|
246
|
-
content += `\nexport { default } from '${formatImportPath(relativeImportPath)}'`
|
|
247
|
-
}
|
|
248
|
-
}
|
|
217
|
+
if(!content) {
|
|
218
|
+
throw new Error(`No content found for ${exportKeyValue}`)
|
|
219
|
+
}
|
|
249
220
|
|
|
250
|
-
if (!content) {
|
|
251
|
-
throw new Error(`No content found for ${exportKeyValue}`)
|
|
252
|
-
}
|
|
253
221
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
222
|
+
const exportObj: BaseExport = {
|
|
223
|
+
type,
|
|
224
|
+
targetFile,
|
|
225
|
+
content
|
|
226
|
+
}
|
|
259
227
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
)
|
|
228
|
+
return exportObj
|
|
229
|
+
}))
|
|
263
230
|
|
|
264
|
-
if
|
|
231
|
+
if(!targetFiles) {
|
|
265
232
|
console.log(`⚠️ No CJS target files for ${key}`)
|
|
266
233
|
}
|
|
267
234
|
|
|
@@ -270,22 +237,14 @@ const extractBaseExportsFromEntry = async (
|
|
|
270
237
|
|
|
271
238
|
const resolvePathWithExtension = async (targetFile: string, extension: string) => {
|
|
272
239
|
try {
|
|
273
|
-
if
|
|
240
|
+
if((await fs.stat(targetFile)).isDirectory()) {
|
|
274
241
|
return `${targetFile}/index.${extension}`
|
|
242
|
+
} else {
|
|
243
|
+
return `${targetFile}.${extension}`
|
|
275
244
|
}
|
|
276
|
-
} catch
|
|
277
|
-
|
|
245
|
+
} catch(e) {
|
|
246
|
+
return `${targetFile}.${extension}`
|
|
278
247
|
}
|
|
279
|
-
|
|
280
|
-
if (targetFile.endsWith(extension)) {
|
|
281
|
-
return targetFile
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
if (targetFile.endsWith(`.js`)) {
|
|
285
|
-
return targetFile.replace(/\.js$/, `.${extension}`)
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
return `${targetFile}.${extension}`
|
|
289
248
|
}
|
|
290
249
|
|
|
291
250
|
const formatImportPath = (exportPath: string): string => {
|
|
@@ -294,7 +253,7 @@ const formatImportPath = (exportPath: string): string => {
|
|
|
294
253
|
|
|
295
254
|
const parseExportPath = async (exportPath: string, cwd = process.cwd()): Promise<string[]> => {
|
|
296
255
|
const split = exportPath.split('*')
|
|
297
|
-
if
|
|
256
|
+
if(split.length === 1) {
|
|
298
257
|
return [exportPath]
|
|
299
258
|
}
|
|
300
259
|
// Allow only 1 * in the path
|
|
@@ -305,15 +264,10 @@ const parseExportPath = async (exportPath: string, cwd = process.cwd()): Promise
|
|
|
305
264
|
return files.map((f) => path.relative(cwd, f))
|
|
306
265
|
}
|
|
307
266
|
|
|
308
|
-
export const buildEsm = async (
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
['swc', 'src', '--strip-leading-paths', '-d', options.destination ?? getDefaultOptions().destination],
|
|
313
|
-
{
|
|
314
|
-
cwd: options.cwd
|
|
315
|
-
}
|
|
316
|
-
)
|
|
267
|
+
export const buildEsm = async (options: BaseOptions = getDefaultOptions()) => {
|
|
268
|
+
await runCommand(`pnpm`, ['swc', 'src', '-d', options.destination ?? getDefaultOptions().destination], {
|
|
269
|
+
cwd: options.cwd
|
|
270
|
+
})
|
|
317
271
|
}
|
|
318
272
|
|
|
319
273
|
const parseExports = async (cwd = process.cwd()): Promise<PackageJson['exports']> => {
|
package/src/clean.ts
CHANGED
|
@@ -8,19 +8,13 @@ export interface CleanOptions extends BaseOptions, Config {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export const clean = async (rawOptions: CleanOptions = getDefaultOptions()) => {
|
|
11
|
-
const {
|
|
12
|
-
cwd,
|
|
13
|
-
destination,
|
|
14
|
-
cleanTs,
|
|
15
|
-
all,
|
|
16
|
-
doNotCleanup: rawDoNotCleanup
|
|
17
|
-
} = {
|
|
11
|
+
const { cwd, destination, cleanTs, all, doNotCleanup: rawDoNotCleanup } = {
|
|
18
12
|
...getDefaultOptions(),
|
|
19
13
|
...rawOptions
|
|
20
14
|
}
|
|
21
15
|
|
|
22
16
|
await validatePackageJson({ command: 'del', cwd })
|
|
23
|
-
const doNotCleanup = rawDoNotCleanup
|
|
17
|
+
const doNotCleanup = rawDoNotCleanup.map((f) => `!${f}`)
|
|
24
18
|
|
|
25
19
|
if (all) {
|
|
26
20
|
await runCommand('pnpm', ['del', '**/*.cjs', '**/*.d.ts', 'tsconfig.tsbuildinfo', ...doNotCleanup], { cwd })
|
|
@@ -40,4 +34,6 @@ export const clean = async (rawOptions: CleanOptions = getDefaultOptions()) => {
|
|
|
40
34
|
{ cwd }
|
|
41
35
|
)
|
|
42
36
|
}
|
|
37
|
+
|
|
38
|
+
|
|
43
39
|
}
|
package/src/config.ts
CHANGED
|
@@ -10,27 +10,23 @@ interface ParseConfigOptions {
|
|
|
10
10
|
cwd?: string
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
const ConfigValidation = z
|
|
14
|
-
.
|
|
15
|
-
|
|
16
|
-
noCJS: z.boolean().optional(),
|
|
17
|
-
copyVerbatim: z.array(z.string())
|
|
18
|
-
})
|
|
19
|
-
.partial()
|
|
13
|
+
const ConfigValidation = z.object({
|
|
14
|
+
doNotCleanup: z.array(z.string()),
|
|
15
|
+
}).partial()
|
|
20
16
|
|
|
21
17
|
export const parseConfig = async (options?: ParseConfigOptions) => {
|
|
22
18
|
const cwd = options?.cwd || process.cwd()
|
|
23
19
|
|
|
24
|
-
let config: unknown
|
|
25
|
-
if
|
|
20
|
+
let config: unknown
|
|
21
|
+
if(options?.config) {
|
|
26
22
|
config = options.config
|
|
27
|
-
} else if
|
|
23
|
+
} else if(options?.configFile) {
|
|
28
24
|
config = await readConfigFile(path.resolve(cwd, options.configFile))
|
|
29
25
|
} else {
|
|
30
26
|
config = await findConfigFile(cwd)
|
|
31
27
|
}
|
|
32
28
|
|
|
33
|
-
if
|
|
29
|
+
if(!config) {
|
|
34
30
|
return {}
|
|
35
31
|
}
|
|
36
32
|
|
|
@@ -39,19 +35,17 @@ export const parseConfig = async (options?: ParseConfigOptions) => {
|
|
|
39
35
|
|
|
40
36
|
const findConfigFile = async (cwd = process.cwd()) => {
|
|
41
37
|
const files = await fs.readdir(cwd)
|
|
42
|
-
const configFile = files.find((f) =>
|
|
43
|
-
|
|
44
|
-
)
|
|
45
|
-
return configFile && (await readConfigFile(path.resolve(cwd, configFile)))
|
|
38
|
+
const configFile = files.find((f) => ['fab.config.js', 'fab.config.cjs', 'fab.config.mjs', 'fabrc.json', '.fabrc'].includes(f))
|
|
39
|
+
return configFile && await readConfigFile(path.resolve(cwd, configFile))
|
|
46
40
|
}
|
|
47
41
|
|
|
48
42
|
const readConfigFile = async (configPath: string): Promise<unknown> => {
|
|
49
|
-
if
|
|
43
|
+
if(/.+\.(js|cjs|mjs)$/.test(configPath)) {
|
|
50
44
|
return (await import(configPath)).default
|
|
51
45
|
}
|
|
52
|
-
if
|
|
46
|
+
if(configPath.endsWith('.json') || configPath.split('/').pop() === '.fabrc') {
|
|
53
47
|
return JSON.parse(await fs.readFile(configPath, 'utf-8'))
|
|
54
48
|
}
|
|
55
49
|
|
|
56
50
|
throw new Error(`Unable to read the config file at ${configPath}`)
|
|
57
|
-
}
|
|
51
|
+
}
|