Skip to content

Commit 13f15e1

Browse files
committed
Merge branch 'master' of https://github.com/mikeal/ipjs
2 parents 6ab72ca + 2fca839 commit 13f15e1

File tree

9 files changed

+23
-21
lines changed

9 files changed

+23
-21
lines changed

cli.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ commands.serve = async args => {
4949
commands.seed = async args => seed(await _argv(args))
5050
*/
5151

52-
const _argv = argv({})
53-
5452
commands.build = async args => build({ ...await argv(build.schema)(args), ...nodeEnv })
5553

5654
commands.publish = async args => {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"ipjs": "cli.js"
99
},
1010
"scripts": {
11-
"test": "estest test/test-*.js"
11+
"test": "standard && estest test/test-*.js"
1212
},
1313
"repository": {
1414
"type": "git",

src/demo/pkg/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { readFileSync } from 'fs'
22
import Block from '@ipld/block/defaults.js'
33

4-
const schema = JSON.parse(readFileSync(new URL('./schema.json', import.meta.url)))
5-
64
const encode = obj => Block.encoder(obj, 'dag-cbor')
75

86
const createPackage = async function * (seedFile) {

src/demo/seed-lite.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import pkg from './pkg/index.js'
22
import ipfs from '@textile/ipfs-lite'
3-
import setup from '@textile/ipfs-lite/dist/setup/index.js'
43
import storage from 'interface-datastore'
54
const { Peer, BlockStore, Block } = ipfs
6-
const { setupLibP2PHost } = setup
75
const { MemoryDatastore } = storage
86

97
const store = new BlockStore(new MemoryDatastore())

src/package/dynamicImports.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const walk = (node, imports = new Set()) => {
33
if (node.type === 'ImportExpression') {
44
if (node.source.value) imports.add(node.source.value)
55
}
6-
for (const [key, value] of Object.entries(node)) {
6+
for (const [, value] of Object.entries(node)) {
77
if (Array.isArray(value)) value.forEach(v => walk(v, imports))
88
else if (typeof value === 'object') walk(value, imports)
99
}

src/package/index.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ import { join } from 'path'
88
import rmtree from '@tgrajewski/rmtree'
99
import preserveShebangs from 'rollup-plugin-preserve-shebangs'
1010

11+
const docFileRegex = /^(readme|license)/i
12+
1113
const copy = o => JSON.parse(JSON.stringify(o))
1214
const vals = Object.values
1315

14-
const { writeFile, mkdir, unlink, readdir, readFile } = fs
16+
const { writeFile, mkdir, unlink, readdir, readFile, copyFile } = fs
1517

1618
const plugins = [ preserveShebangs.preserveShebangs() ]
1719

@@ -72,6 +74,7 @@ class Package {
7274
}
7375
this.exports = exports
7476
let promises = [...this.files.values()]
77+
this.docFiles = new Map((await this.getDocFiles()).map(f => [f, toURL(f)]))
7578
if (this.includeTests) {
7679
const testFiles = await this.getTestFiles()
7780
this.tests = new Map(testFiles.map(k => [k, this.testFile(toURL(k))]))
@@ -104,6 +107,10 @@ class Package {
104107
return this.pkgjson.exports[key]
105108
}
106109

110+
async getDocFiles () {
111+
return (await readdir(this.cwd)).filter(f => docFileRegex.test(f))
112+
}
113+
107114
async getTestFiles () {
108115
const files = await readdir(this.cwd)
109116
const testFiles = []
@@ -159,11 +166,13 @@ class Package {
159166
async deflate (dist) {
160167
if (!(dist instanceof URL)) dist = path(dist)
161168
rmtree(fileURLToPath(dist))
162-
await mkdir(dist)
163-
await mkdir(new URL(dist + '/cjs'))
169+
await mkdir(new URL(dist + '/cjs'), { recursive: true })
164170
await mkdir(new URL(dist + '/esm'))
165171

166172
const pending = [...this.files.values()].map(p => p.then(f => f.deflate(dist)))
173+
for (const [f, url] of this.docFiles) {
174+
pending.push(copyFile(url, new URL(`${dist}/${f}`)))
175+
}
167176
if (this.includeTests) {
168177
pending.push(...[...this.testFiles.values()].map(p => p.then(f => f.deflate(dist))))
169178
}

src/package/testFile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import dynamicImports from './dynamicImports.js'
77

88
const { File, writeFile } = file
99

10-
const { readFile, mkdir } = fs
10+
const { readFile } = fs
1111
const { generate } = astring
1212

1313
const stropts = { format: { indent: { style: ' ' } } }
@@ -41,7 +41,7 @@ class TestFile extends File {
4141
const rel = p => {
4242
const u = pathToFileURL(this.pkg.cwd)
4343
const r = this.url.toString().slice(u.toString().length + 1)
44-
const pre = (r.match(/\//g) || []).map(() => '../').join('')
44+
let pre = (r.match(/\//g) || []).map(() => '../').join('')
4545
if (!pre.length) pre = './'
4646
return pre + p.slice(2)
4747
}

src/package/worker.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Worker, isMainThread, parentPort, workerData } from 'worker_threads'
2-
import { fileURLToPath, pathToFileURL } from 'url'
2+
import { fileURLToPath } from 'url'
33
import { promises as fs } from 'fs'
44
import acorn from 'acorn'
55
import astring from 'escodegen'
@@ -73,9 +73,6 @@ const run = async () => {
7373
return writeFile(url, data)
7474
}
7575

76-
let cjsCompile
77-
let esmCompile
78-
7976
const commands = {}
8077
commands.deflate = async (dist, cwd) => {
8178
const path = fileURLToPath(url)
@@ -93,8 +90,8 @@ const run = async () => {
9390
})
9491
parentPort.postMessage({ id: 'init', ret: imports })
9592
convert(cjs)
96-
cjsCompile = generate(cjs, stropts)
97-
esmCompile = generate(program, stropts)
93+
const cjsCompile = generate(cjs, stropts)
94+
const esmCompile = generate(program, stropts)
9895
}
9996

10097
let mod = null

src/run.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import pathToUrl from './path-to-url.js'
22
import api from './api.js'
33
// import IPFS from 'ipfs'
4-
import Block from '@ipld/block/defaults.js'
4+
// import Block from '@ipld/block/defaults.js'
55
import { client } from './demo/registry/index.js'
66
import { fromModule } from './util.js'
7-
import { promises as fs } from 'fs'
7+
// import { promises as fs } from 'fs'
88

9+
/*
910
const getIPFS = cid => IPFS.create({
1011
repo: `/tmp/ipjs-${cid}`,
1112
silent: true,
@@ -18,6 +19,7 @@ const getIPFS = cid => IPFS.create({
1819
}
1920
}
2021
})
22+
*/
2123

2224
const fromPackage = pkg => {
2325
const buffer = Buffer.from(pkg.nodejs)

0 commit comments

Comments
 (0)