@yopem-ui/cli 0.1.1 → 0.1.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yopem-ui/cli",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "CLI for installing Yopem UI source components and StyleX setup",
5
5
  "keywords": [
6
6
  "cli",
package/src/init.ts CHANGED
@@ -1519,10 +1519,11 @@ function nextScripts(value: JsonValue | undefined) {
1519
1519
  }
1520
1520
 
1521
1521
  async function chooseFile(root: string, names: string[], fallback?: string) {
1522
- const matches: string[] = []
1522
+ const existing = await Promise.all(
1523
+ names.map((name) => existingFile(root, name)),
1524
+ )
1523
1525
 
1524
- for (const name of names)
1525
- if (await existingFile(root, name)) matches.push(name)
1526
+ const matches = names.filter((_, index) => existing[index])
1526
1527
 
1527
1528
  if (matches.length > 1)
1528
1529
  throw new Error(`Ambiguous configuration: ${matches.join(", ")}`)
@@ -1619,8 +1620,11 @@ export async function initProject(
1619
1620
  }
1620
1621
  }
1621
1622
 
1622
- const packageRun = await packageRunner(root, options.run)
1623
- const uiRun = await packageRunner(uiRoot, options.run)
1623
+ const [packageRun, uiRun] = await Promise.all([
1624
+ packageRunner(root, options.run),
1625
+ packageRunner(uiRoot, options.run),
1626
+ ])
1627
+
1624
1628
  const edits = new Map<string, { before: string | null; after: string }>()
1625
1629
 
1626
1630
  const plannedFiles: {
package/src/install.ts CHANGED
@@ -490,26 +490,34 @@ export async function writeFiles(
490
490
  }
491
491
 
492
492
  try {
493
- for (const [path, change] of changes) {
494
- const exists = await existingFile(root, path)
495
- const before = exists ? await readFile(join(root, path)) : null
496
-
497
- if ((before?.toString("utf8") ?? null) !== change.before) {
498
- throw new Error(`File changed before commit: ${path}`)
499
- }
500
-
501
- const mode = exists ? (await lstat(join(root, path))).mode & 0o7777 : null
502
- const after = change.after === null ? null : Buffer.from(change.after)
503
- staged.push({
504
- path,
505
- before,
506
- after,
507
- mode,
508
- afterMode: mode,
509
- changed: change.before !== change.after,
510
- directory: null,
511
- })
512
- }
493
+ staged.push(
494
+ ...(await Promise.all(
495
+ [...changes].map(async ([path, change]): Promise<StagedFile> => {
496
+ const exists = await existingFile(root, path)
497
+ const before = exists ? await readFile(join(root, path)) : null
498
+
499
+ if ((before?.toString("utf8") ?? null) !== change.before) {
500
+ throw new Error(`File changed before commit: ${path}`)
501
+ }
502
+
503
+ const mode = exists
504
+ ? (await lstat(join(root, path))).mode & 0o7777
505
+ : null
506
+
507
+ const after = change.after === null ? null : Buffer.from(change.after)
508
+
509
+ return {
510
+ path,
511
+ before,
512
+ after,
513
+ mode,
514
+ afterMode: mode,
515
+ changed: change.before !== change.after,
516
+ directory: null,
517
+ }
518
+ }),
519
+ )),
520
+ )
513
521
 
514
522
  for (const file of staged) {
515
523
  if (!file.changed) continue
@@ -535,7 +543,9 @@ export async function writeFiles(
535
543
 
536
544
  await prepare?.()
537
545
 
538
- for (const file of staged) await verify(file, file.before, file.mode)
546
+ await Promise.all(
547
+ staged.map((file) => verify(file, file.before, file.mode)),
548
+ )
539
549
 
540
550
  for (const file of staged) {
541
551
  if (!file.changed) continue
@@ -737,10 +747,16 @@ export async function planInstall(name: string, options: InstallOptions = {}) {
737
747
  manifest.provenance[path] = { registryUrl, items: ownership }
738
748
  }
739
749
 
740
- for (const [path, file] of files) {
741
- const exists = await existingFile(root, path)
750
+ const currentFiles = await Promise.all(
751
+ [...files].map(async ([path, file]) => {
752
+ const exists = await existingFile(root, path)
753
+ const before = exists ? await readFile(join(root, path), "utf8") : null
754
+
755
+ return { path, file, before }
756
+ }),
757
+ )
742
758
 
743
- const before = exists ? await readFile(join(root, path), "utf8") : null
759
+ for (const { path, file, before } of currentFiles) {
744
760
  const current = before === null ? null : hash(before)
745
761
  changes.set(path, { before, after: before })
746
762
  const previous = manifest.files[path]
package/src/project.ts CHANGED
@@ -166,8 +166,12 @@ async function packageManager(root: string) {
166
166
  ["yarn", "yarn.lock"],
167
167
  ]
168
168
 
169
- for (const [manager, path] of locks) {
170
- if (await existingFile(root, path)) found.add(manager)
169
+ const existingLocks = await Promise.all(
170
+ locks.map(([, path]) => existingFile(root, path)),
171
+ )
172
+
173
+ for (const [index, [manager]] of locks.entries()) {
174
+ if (existingLocks[index]) found.add(manager)
171
175
  }
172
176
 
173
177
  if (found.size > 1) {
@@ -184,8 +188,12 @@ export async function packageRunner(
184
188
  run?: InstallOptions["run"],
185
189
  ): Promise<NonNullable<InstallOptions["run"]>> {
186
190
  const target = await realpath(root)
187
- const owner = await workspaceRoot(target)
188
- const local = await packageManager(target)
191
+
192
+ const [owner, local] = await Promise.all([
193
+ workspaceRoot(target),
194
+ packageManager(target),
195
+ ])
196
+
189
197
  const workspace = owner === target ? local : await packageManager(owner)
190
198
 
191
199
  if (local && workspace && local !== workspace) {