Skip to content

Commit

Permalink
fix: ensure parent dir for link
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Apr 9, 2021
1 parent 7ff156c commit 87e75b3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
11 changes: 6 additions & 5 deletions src/build.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { promisify } from 'util'
import Module from 'module'
import { unlink } from 'fs/promises'
import mkdirp from 'mkdirp'
import { resolve, basename } from 'upath'
import chalk from 'chalk'
import consola from 'consola'
import rimraf from 'rimraf'
import mkdirp from 'mkdirp'
import defu from 'defu'
import prettyBytes from 'pretty-bytes'
import jiti from 'jiti'
Expand Down Expand Up @@ -65,7 +65,7 @@ export async function build (rootDir: string, stub: boolean) {
}

// Start info
consola.info(chalk.cyan(`Building ${pkg.name}`))
consola.info(chalk.cyan(`${ctx.stub ? 'Stubbing' : 'Building'} ${pkg.name}`))
if (process.env.DEBUG) {
consola.info(`${chalk.bold('Root dir:')} ${ctx.rootDir}
${chalk.bold('Entries:')}
Expand All @@ -81,9 +81,10 @@ export async function build (rootDir: string, stub: boolean) {
await mkdirp(outDir)
}

// selflink
if (ctx.stub) {
await symlink(resolve(ctx.rootDir), resolve(ctx.rootDir, 'node_modules', ctx.pkg.name))
// Try to selflink
if (ctx.stub && ctx.pkg.name) {
const nodemodulesDir = resolve(ctx.rootDir, 'node_modules', ctx.pkg.name)
await symlink(resolve(ctx.rootDir), nodemodulesDir).catch(() => {})
}

// untyped
Expand Down
6 changes: 5 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ import fsp from 'fs/promises'
import { dirname } from 'upath'
import mkdirp from 'mkdirp'

export async function ensuredir (path: string) {
await mkdirp(dirname(path))
}

export async function symlink (from: string, to: string, force: boolean = true) {
await mkdirp(dirname(from))
await ensuredir(to)
if (force) {
await fsp.unlink(to).catch(() => { })
}
Expand Down

0 comments on commit 87e75b3

Please sign in to comment.