@driveflux/fab 1.0.4 → 1.0.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.
@@ -1,13 +1,13 @@
1
1
 
2
- > @driveflux/fab@1.0.4 build /Users/flux/Projects/flux/packages/fab
2
+ > @driveflux/fab@1.0.6 build /Users/flux/Projects/flux/packages/fab
3
3
  > pnpm build:js && pnpm build:types
4
4
 
5
5
 
6
- > @driveflux/fab@1.0.4 build:js /Users/flux/Projects/flux/packages/fab
6
+ > @driveflux/fab@1.0.6 build:js /Users/flux/Projects/flux/packages/fab
7
7
  > swc src --strip-leading-paths -d dist
8
8
 
9
- Successfully compiled: 7 files with swc (179.57ms)
9
+ Successfully compiled: 7 files with swc (279.89ms)
10
10
 
11
- > @driveflux/fab@1.0.4 build:types /Users/flux/Projects/flux/packages/fab
11
+ > @driveflux/fab@1.0.6 build:types /Users/flux/Projects/flux/packages/fab
12
12
  > tsc --build --emitDeclarationOnly
13
13
 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @driveflux/fab
2
2
 
3
+ ## 1.0.6
4
+
5
+ ### Patch Changes
6
+
7
+ - Minor diversion version fix
8
+
9
+ ## 1.0.5
10
+
11
+ ### Patch Changes
12
+
13
+ - Upgraded packages again
14
+
3
15
  ## 1.0.4
4
16
 
5
17
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAC5C,OAAO,EAAE,YAAY,EAAS,MAAM,YAAY,CAAA;AAChD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAK7C,UAAU,YAAa,SAAQ,WAAW,EAAE,sBAAsB,EAAE,YAAY;IAC9E,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;CACxB;AAED,UAAU,sBAAuB,SAAQ,WAAW;IAClD,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,OAAO,CAAC,EAAE,WAAW,CAAC,SAAS,CAAC,CAAA;CACjC;AAaD,eAAO,MAAM,KAAK,gBAAuB,YAAY,kBA2BpD,CAAA;AAED,eAAO,MAAM,YAAY,gBAAuB,YAAY,kBAc3D,CAAA;AAED,eAAO,MAAM,UAAU,gBAAuB,WAAW,kBAIxD,CAAA;AAED,eAAO,MAAM,QAAQ,gBAAuB,WAAW,kBAgBtD,CAAA;AAED,eAAO,MAAM,eAAe,gBAAuB,sBAAsB,sBAoBxE,CAAA;AAgLD,eAAO,MAAM,QAAQ,gBAAuB,WAAW,kBAKtD,CAAA"}
1
+ {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAC5C,OAAO,EAAE,YAAY,EAAS,MAAM,YAAY,CAAA;AAChD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAK7C,UAAU,YAAa,SAAQ,WAAW,EAAE,sBAAsB,EAAE,YAAY;IAC9E,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;CACxB;AAED,UAAU,sBAAuB,SAAQ,WAAW;IAClD,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,OAAO,CAAC,EAAE,WAAW,CAAC,SAAS,CAAC,CAAA;CACjC;AAaD,eAAO,MAAM,KAAK,gBAAuB,YAAY,kBA2BpD,CAAA;AAED,eAAO,MAAM,YAAY,gBAAuB,YAAY,kBAgB3D,CAAA;AAED,eAAO,MAAM,UAAU,gBAAuB,WAAW,kBAIxD,CAAA;AAED,eAAO,MAAM,QAAQ,gBAAuB,WAAW,kBAkBtD,CAAA;AAED,eAAO,MAAM,eAAe,gBAAuB,sBAAsB,sBAoBxE,CAAA;AAmLD,eAAO,MAAM,QAAQ,gBAAuB,WAAW,kBAStD,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"clean.d.ts","sourceRoot":"","sources":["../src/clean.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAE7C,MAAM,WAAW,YAAa,SAAQ,WAAW,EAAE,MAAM;IACvD,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,GAAG,CAAC,EAAE,OAAO,CAAA;CACd;AAED,eAAO,MAAM,KAAK,gBAAsB,YAAY,kBA6BnD,CAAA"}
1
+ {"version":3,"file":"clean.d.ts","sourceRoot":"","sources":["../src/clean.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAE7C,MAAM,WAAW,YAAa,SAAQ,WAAW,EAAE,MAAM;IACvD,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,GAAG,CAAC,EAAE,OAAO,CAAA;CACd;AAED,eAAO,MAAM,KAAK,gBAAsB,YAAY,kBAiCnD,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAA;AAErD,UAAU,kBAAkB;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,GAAG,CAAC,EAAE,MAAM,CAAA;CACb;AAED,QAAA,MAAM,gBAAgB;;;;;;;;;;;;EAIV,CAAA;AAEZ,eAAO,MAAM,WAAW,aAAoB,kBAAkB;;;;EAiB7D,CAAA"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAA;AAErD,UAAU,kBAAkB;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,GAAG,CAAC,EAAE,MAAM,CAAA;CACb;AAED,QAAA,MAAM,gBAAgB;;;;;;;;;;;;EAMV,CAAA;AAEZ,eAAO,MAAM,WAAW,aAAoB,kBAAkB;;;;EAiB7D,CAAA"}
@@ -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,+FAAsG,aAAa,kBAqCrI,CAAA"}
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,+FAMhB,aAAa,kBAuCf,CAAA"}
@@ -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,SAAS,WAAW,CAAC,GAAG,MAMzD,CAAA"}
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,CAAC,GAAG,MAK3D,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@driveflux/fab",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "type": "module",
5
5
  "types": "./dist/index.d.ts",
6
6
  "bin": {
package/src/build.ts CHANGED
@@ -57,24 +57,26 @@ export const build = async (rawOptions?: BuildOptions) => {
57
57
  await Promise.all(promises)
58
58
 
59
59
  // Make exports for CJS
60
- if(!options.noCJS) {
60
+ if (!options.noCJS) {
61
61
  await makeBaseExports(options)
62
62
  }
63
63
  }
64
64
 
65
65
  export const copyVerbatim = async (rawOptions?: BuildOptions) => {
66
66
  const options = merge({}, getDefaultOptions(), rawOptions)
67
- if(options.copyVerbatim?.length) {
67
+ if (options.copyVerbatim?.length) {
68
68
  const cwd = options.cwd ?? process.cwd()
69
69
  const destination = options.destination ?? getDefaultOptions().destination
70
- await Promise.all(options.copyVerbatim.map(async (fileOrFolderRaw) => {
71
- const fileOrFolder = `src/${fileOrFolderRaw.replace(/^(\/)*src/, '')}`
72
- const targetPath = path.resolve(destination, fileOrFolder).replace('/src', '')
73
- const targetPathCjs = path.resolve(destination, 'cjs', fileOrFolder).replace('/src', '')
74
- await ensureDir(path.dirname(targetPath))
75
- await fs.cp(path.resolve(cwd, fileOrFolder), targetPath, { recursive: true })
76
- await fs.cp(path.resolve(cwd, fileOrFolder), targetPathCjs, { recursive: true })
77
- }))
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
+ )
78
80
  }
79
81
  }
80
82
 
@@ -91,7 +93,9 @@ export const buildCjs = async (rawOptions?: BaseOptions) => {
91
93
  const cjsPath = path.resolve(destination, 'cjs')
92
94
  await validatePackageJson({ command: 'swc', cwd })
93
95
  // We start by emitting the CJS files
94
- await runCommand(`pnpm`, ['swc', 'src', '-C', 'module.type=commonjs', '--strip-leading-paths', '-d', cjsPath], { cwd })
96
+ await runCommand(`pnpm`, ['swc', 'src', '-C', 'module.type=commonjs', '--strip-leading-paths', '-d', cjsPath], {
97
+ cwd
98
+ })
95
99
  const targetPath = path.resolve(cwd, cjsPath, 'package.json')
96
100
  await ensureDir(path.dirname(targetPath))
97
101
  await fs.writeFile(
@@ -186,75 +190,78 @@ const extractBaseExportsFromEntry = async (
186
190
  throw new Error(`Only strings are allowed in the "${exportTypeKey}" field`)
187
191
  }
188
192
 
189
- const asteriskPosition = exportKeyValue.replace('./', '').split('/').findIndex((p) => p.startsWith('*'))
193
+ const asteriskPosition = exportKeyValue
194
+ .replace('./', '')
195
+ .split('/')
196
+ .findIndex((p) => p.startsWith('*'))
190
197
  const paths = await parseExportPath(exportKeyValue, cwd)
191
198
 
192
- const targetFiles = Promise.all(paths.map(async (p) => {
193
- let finalKey = key
194
- if (hasWildcard) {
195
- finalKey = key.replace(
196
- '*',
197
- p
198
- .split('/')
199
- .slice(asteriskPosition, asteriskPosition + 1)
200
- .join('/')
201
- )
202
- }
199
+ const targetFiles = Promise.all(
200
+ paths.map(async (p) => {
201
+ let finalKey = key
202
+ if (hasWildcard) {
203
+ finalKey = key.replace(
204
+ '*',
205
+ p
206
+ .split('/')
207
+ .slice(asteriskPosition, asteriskPosition + 1)
208
+ .join('/')
209
+ )
210
+ }
203
211
 
204
- if (finalKey === '.' || finalKey === './') {
205
- finalKey = 'index'
206
- }
212
+ if (finalKey === '.' || finalKey === './') {
213
+ finalKey = 'index'
214
+ }
207
215
 
208
- let content = ''
209
- let targetFile: string = ''
216
+ let content = ''
217
+ let targetFile: string = ''
210
218
 
211
- const geImportPaths = (importPath: string) => {
212
- const targetFile = path.resolve(cwd, importPath)
213
- const importFromPath = path.dirname(targetFile)
214
- const fullImportPath = path.resolve(cwd, p)
215
- const relativeImportPath = path.relative(importFromPath, fullImportPath)
216
- return { relativeImportPath, fullImportPath, targetFile }
217
- }
218
-
219
-
220
- if (type === 'cjs') {
221
- finalKey = await resolvePathWithExtension(finalKey, 'cjs')
222
- const importPaths = geImportPaths(finalKey)
223
- const relativeImportPath = importPaths.relativeImportPath
224
- targetFile = importPaths.targetFile
225
- content = `module.exports = require('${formatImportPath(relativeImportPath)}')`
226
- }
219
+ const geImportPaths = (importPath: string) => {
220
+ const targetFile = path.resolve(cwd, importPath)
221
+ const importFromPath = path.dirname(targetFile)
222
+ const fullImportPath = path.resolve(cwd, p)
223
+ const relativeImportPath = path.relative(importFromPath, fullImportPath)
224
+ return { relativeImportPath, fullImportPath, targetFile }
225
+ }
227
226
 
228
- if (type === 'types') {
229
- finalKey = await resolvePathWithExtension(finalKey, 'd.ts')
230
- const importPaths = geImportPaths(finalKey)
231
- const relativeImportPath = importPaths.relativeImportPath
232
- targetFile = importPaths.targetFile
233
- // Typescript will complain about exprting .d.ts, so we just omt that
234
- content = `export * from '${formatImportPath(relativeImportPath).replace('.d.ts', '')}'`
235
-
236
- // Now, let's go inside that file and see if it exports "default" and add that into the content
237
- const fileContent = await fs.readFile(importPaths.fullImportPath, 'utf-8')
238
- if (/export default/.test(fileContent)) {
239
- content += `\nexport { default } from '${formatImportPath(relativeImportPath)}'`
227
+ if (type === 'cjs') {
228
+ finalKey = await resolvePathWithExtension(finalKey, 'cjs')
229
+ const importPaths = geImportPaths(finalKey)
230
+ const relativeImportPath = importPaths.relativeImportPath
231
+ targetFile = importPaths.targetFile
232
+ content = `module.exports = require('${formatImportPath(relativeImportPath)}')`
240
233
  }
241
- }
242
234
 
243
- if(!content) {
244
- throw new Error(`No content found for ${exportKeyValue}`)
245
- }
235
+ if (type === 'types') {
236
+ finalKey = await resolvePathWithExtension(finalKey, 'd.ts')
237
+ const importPaths = geImportPaths(finalKey)
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
+ }
246
249
 
250
+ if (!content) {
251
+ throw new Error(`No content found for ${exportKeyValue}`)
252
+ }
247
253
 
248
- const exportObj: BaseExport = {
249
- type,
250
- targetFile,
251
- content
252
- }
254
+ const exportObj: BaseExport = {
255
+ type,
256
+ targetFile,
257
+ content
258
+ }
253
259
 
254
- return exportObj
255
- }))
260
+ return exportObj
261
+ })
262
+ )
256
263
 
257
- if(!targetFiles) {
264
+ if (!targetFiles) {
258
265
  console.log(`⚠️ No CJS target files for ${key}`)
259
266
  }
260
267
 
@@ -263,18 +270,18 @@ const extractBaseExportsFromEntry = async (
263
270
 
264
271
  const resolvePathWithExtension = async (targetFile: string, extension: string) => {
265
272
  try {
266
- if((await fs.stat(targetFile)).isDirectory()) {
273
+ if ((await fs.stat(targetFile)).isDirectory()) {
267
274
  return `${targetFile}/index.${extension}`
268
275
  }
269
- } catch(e) {
276
+ } catch (e) {
270
277
  // Nothing to do here
271
278
  }
272
279
 
273
- if(targetFile.endsWith(extension)) {
280
+ if (targetFile.endsWith(extension)) {
274
281
  return targetFile
275
282
  }
276
283
 
277
- if(targetFile.endsWith(`.js`)) {
284
+ if (targetFile.endsWith(`.js`)) {
278
285
  return targetFile.replace(/\.js$/, `.${extension}`)
279
286
  }
280
287
 
@@ -287,7 +294,7 @@ const formatImportPath = (exportPath: string): string => {
287
294
 
288
295
  const parseExportPath = async (exportPath: string, cwd = process.cwd()): Promise<string[]> => {
289
296
  const split = exportPath.split('*')
290
- if(split.length === 1) {
297
+ if (split.length === 1) {
291
298
  return [exportPath]
292
299
  }
293
300
  // Allow only 1 * in the path
@@ -300,9 +307,13 @@ const parseExportPath = async (exportPath: string, cwd = process.cwd()): Promise
300
307
 
301
308
  export const buildEsm = async (rawOptions?: BaseOptions) => {
302
309
  const options = merge({}, getDefaultOptions(), rawOptions)
303
- await runCommand(`pnpm`, ['swc', 'src', '--strip-leading-paths', '-d', options.destination ?? getDefaultOptions().destination], {
304
- cwd: options.cwd
305
- })
310
+ await runCommand(
311
+ `pnpm`,
312
+ ['swc', 'src', '--strip-leading-paths', '-d', options.destination ?? getDefaultOptions().destination],
313
+ {
314
+ cwd: options.cwd
315
+ }
316
+ )
306
317
  }
307
318
 
308
319
  const parseExports = async (cwd = process.cwd()): Promise<PackageJson['exports']> => {
package/src/clean.ts CHANGED
@@ -8,7 +8,13 @@ export interface CleanOptions extends BaseOptions, Config {
8
8
  }
9
9
 
10
10
  export const clean = async (rawOptions: CleanOptions = getDefaultOptions()) => {
11
- const { cwd, destination, cleanTs, all, doNotCleanup: rawDoNotCleanup } = {
11
+ const {
12
+ cwd,
13
+ destination,
14
+ cleanTs,
15
+ all,
16
+ doNotCleanup: rawDoNotCleanup
17
+ } = {
12
18
  ...getDefaultOptions(),
13
19
  ...rawOptions
14
20
  }
@@ -34,6 +40,4 @@ export const clean = async (rawOptions: CleanOptions = getDefaultOptions()) => {
34
40
  { cwd }
35
41
  )
36
42
  }
37
-
38
-
39
43
  }
package/src/config.ts CHANGED
@@ -10,25 +10,27 @@ interface ParseConfigOptions {
10
10
  cwd?: string
11
11
  }
12
12
 
13
- const ConfigValidation = z.object({
14
- doNotCleanup: z.array(z.string()),
15
- noCJS: z.boolean().optional(),
16
- copyVerbatim: z.array(z.string()),
17
- }).partial()
13
+ const ConfigValidation = z
14
+ .object({
15
+ doNotCleanup: z.array(z.string()),
16
+ noCJS: z.boolean().optional(),
17
+ copyVerbatim: z.array(z.string())
18
+ })
19
+ .partial()
18
20
 
19
21
  export const parseConfig = async (options?: ParseConfigOptions) => {
20
22
  const cwd = options?.cwd || process.cwd()
21
23
 
22
- let config: unknown
23
- if(options?.config) {
24
+ let config: unknown
25
+ if (options?.config) {
24
26
  config = options.config
25
- } else if(options?.configFile) {
27
+ } else if (options?.configFile) {
26
28
  config = await readConfigFile(path.resolve(cwd, options.configFile))
27
29
  } else {
28
30
  config = await findConfigFile(cwd)
29
31
  }
30
32
 
31
- if(!config) {
33
+ if (!config) {
32
34
  return {}
33
35
  }
34
36
 
@@ -37,17 +39,19 @@ export const parseConfig = async (options?: ParseConfigOptions) => {
37
39
 
38
40
  const findConfigFile = async (cwd = process.cwd()) => {
39
41
  const files = await fs.readdir(cwd)
40
- const configFile = files.find((f) => ['fab.config.js', 'fab.config.cjs', 'fab.config.mjs', 'fabrc.json', '.fabrc'].includes(f))
41
- return configFile && await readConfigFile(path.resolve(cwd, configFile))
42
+ const configFile = files.find((f) =>
43
+ ['fab.config.js', 'fab.config.cjs', 'fab.config.mjs', 'fabrc.json', '.fabrc'].includes(f)
44
+ )
45
+ return configFile && (await readConfigFile(path.resolve(cwd, configFile)))
42
46
  }
43
47
 
44
48
  const readConfigFile = async (configPath: string): Promise<unknown> => {
45
- if(/.+\.(js|cjs|mjs)$/.test(configPath)) {
49
+ if (/.+\.(js|cjs|mjs)$/.test(configPath)) {
46
50
  return (await import(configPath)).default
47
51
  }
48
- if(configPath.endsWith('.json') || configPath.split('/').pop() === '.fabrc') {
52
+ if (configPath.endsWith('.json') || configPath.split('/').pop() === '.fabrc') {
49
53
  return JSON.parse(await fs.readFile(configPath, 'utf-8'))
50
54
  }
51
55
 
52
56
  throw new Error(`Unable to read the config file at ${configPath}`)
53
- }
57
+ }
package/src/create.ts CHANGED
@@ -10,21 +10,29 @@ interface CreateOptions {
10
10
  dangerouslyRewrite?: boolean
11
11
  }
12
12
 
13
- export const create = async ({ template, name, destination: providedDestination, cwd: providedCwd, dangerouslyRewrite }: CreateOptions) => {
13
+ export const create = async ({
14
+ template,
15
+ name,
16
+ destination: providedDestination,
17
+ cwd: providedCwd,
18
+ dangerouslyRewrite
19
+ }: CreateOptions) => {
14
20
  const cwd = providedCwd ?? process.cwd()
15
21
  const destination = providedDestination ? path.resolve(cwd, providedDestination) : cwd
16
22
  const finalDestination = path.resolve(destination, name)
17
23
  // Make sure we don't overwite stuff
18
24
  try {
19
- if((await fs.stat(finalDestination))) {
20
- if(!dangerouslyRewrite) {
21
- console.log(`🚨 Cannot create the pacakge at ${finalDestination}. Please delete the previous file or directory or use "dangerouslyRewrite"`)
25
+ if (await fs.stat(finalDestination)) {
26
+ if (!dangerouslyRewrite) {
27
+ console.log(
28
+ `🚨 Cannot create the pacakge at ${finalDestination}. Please delete the previous file or directory or use "dangerouslyRewrite"`
29
+ )
22
30
  process.exit(1)
23
31
  } else {
24
32
  await deleteAsync(finalDestination)
25
33
  }
26
34
  }
27
- } catch(e) {
35
+ } catch (e) {
28
36
  // Nothing to do
29
37
  }
30
38
 
@@ -34,13 +42,13 @@ export const create = async ({ template, name, destination: providedDestination,
34
42
  const templatePath = path.resolve(getBaseDir(), `templates/${template}`)
35
43
 
36
44
  // Make sure the template exists
37
- if(!(await fs.stat(templatePath)).isDirectory()) {
45
+ if (!(await fs.stat(templatePath)).isDirectory()) {
38
46
  throw new Error(`The template ${template} doesn't exist`)
39
47
  }
40
48
 
41
49
  // First, copy the template into the destintion
42
50
  await fs.cp(templatePath, finalDestination, {
43
- recursive: true,
51
+ recursive: true
44
52
  })
45
53
 
46
54
  // Now we insert the name into the package file
@@ -51,10 +59,10 @@ export const create = async ({ template, name, destination: providedDestination,
51
59
 
52
60
  const replaceInFile = async (filePath: string, replacements: Record<string, string>) => {
53
61
  // Load the file
54
- const content = await fs.readFile(filePath, 'utf-8')
62
+ const content = await fs.readFile(filePath, 'utf-8')
55
63
 
56
64
  // No time to build the regex and replace logic, that's for later, we just replace the name now
57
65
  const newContent = content.replace('{{name}}', replacements.name)
58
66
 
59
67
  await fs.writeFile(filePath, newContent)
60
- }
68
+ }
package/src/types.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export interface BaseOptions {
2
2
  cwd?: string
3
3
  destination?: string
4
- }
4
+ }
package/src/utils.ts CHANGED
@@ -76,10 +76,9 @@ export const getBaseDir = () => {
76
76
  return path.resolve(path.dirname(decodeURIComponent(new URL(import.meta.url).pathname)), '..')
77
77
  }
78
78
 
79
- export const getDefaultOptions = (): Required<BaseOptions> & Config =>
80
- ({
81
- cwd: process.cwd(),
82
- destination: 'dist',
83
- doNotCleanup: ['src', 'bin'],
84
- noCJS: false,
85
- })
79
+ export const getDefaultOptions = (): Required<BaseOptions> & Config => ({
80
+ cwd: process.cwd(),
81
+ destination: 'dist',
82
+ doNotCleanup: ['src', 'bin'],
83
+ noCJS: false
84
+ })
@@ -0,0 +1 @@
1
+ // TODO: remove this file
@@ -24,7 +24,7 @@
24
24
  "@driveflux/eslint-config": "workspace:*",
25
25
  "@driveflux/fab": "workspace:*",
26
26
  "@swc/cli": "^0.1.63",
27
- "@swc/core": "1.3.105",
27
+ "@swc/core": "1.4.17",
28
28
  "@types/lodash": "^4.14.202",
29
29
  "@types/node": "^20.9.1",
30
30
  "del-cli": "^5.1.0",
@@ -0,0 +1 @@
1
+ // TODO: remove this file