Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: work with browserify #13

Merged
merged 1 commit into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions src/package/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { promises as fs } from 'fs'
import { promises as fs, existsSync } from 'fs'
import { rollup } from 'rollup'
import file from './file.js'
import testFile from './testFile.js'
import path from '../path-to-url.js'
import { fileURLToPath } from 'url'
import { join } from 'path'
import { join, dirname } from 'path'
import rmtree from '@tgrajewski/rmtree'
import preserveShebangs from 'rollup-plugin-preserve-shebangs'

Expand Down Expand Up @@ -163,6 +163,37 @@ class Package {
await unlink(new URL(dist + '/cjs/_ipjsInput.js'))
}

async stubFiles (dist, files) {
await Promise.all(
files.map(async (file) => {
if (file === '.') {
file = 'index.js'
}
if (file.startsWith('./')) {
file = file.substring(2)
}
const dir = dirname(file)
if (dir !== '.') {
try {
await mkdir(new URL(dist + '/' + dir), {
recursive: true
})
} catch (err) {
if (err.code !== 'EEXIST') {
throw err
}
}
}

if (existsSync(new URL(dist + '/' + file))) {
return
}

await writeFile(new URL(dist + '/' + file), '')
})
)
}

async deflate (dist) {
if (!(dist instanceof URL)) dist = path(dist)
rmtree(fileURLToPath(dist))
Expand Down Expand Up @@ -204,6 +235,7 @@ class Package {
json.exports = json.exports.import
json.browser = json.browser.import
}
await this.stubFiles(dist, Object.keys(json.browser))
let files = Promise.all(pending)
pending.push(writeFile(new URL(dist + '/package.json'), JSON.stringify(json, null, 2)))
const typeModule = '{ "type" : "module" }'
Expand Down
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.