Skip to content

Commit

Permalink
fix stream bug
Browse files Browse the repository at this point in the history
  • Loading branch information
z-vr committed Oct 22, 2019
1 parent caf855c commit 3d12af8
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 32 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,5 @@ typings/
t
matrix
.COPYING
.LICENSE
.LICENSE
alamode
19 changes: 19 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,24 @@
"<node_internals>/**/*.js"
]
},
{
"type": "node",
"request": "launch",
"name": "Launch Splendid",
"program": "${workspaceFolder}/alamode/bin/alamode.js",
"cwd": "${workspaceFolder}/../../adc/splendid",
"env": {
"NODE_DEBUG": "alamode",
"ALAMODE_ENV": "build"
},
"args": [
// "src", "-o", "buildd", // source
"src", "-o", "t.js", "-s", "-i", "bin/.eslintrc,js", "-e", "js",
],
"console": "integratedTerminal",
"skipFiles": [
"<node_internals>/**/*.js"
]
},
]
}
21 changes: 10 additions & 11 deletions compile/bin/alamode.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,13 @@ class Ua extends Sa {
return this.P;
}
}
const I = async a => {
const Va = async a => {
({b:a} = new Ua({rs:a, U:C(!0)}));
return await a;
};
async function Va(a) {
async function I(a) {
a = x(a);
return await I(a);
return await Va(a);
}
;async function Wa(a, b) {
if (!a) {
Expand Down Expand Up @@ -697,7 +697,7 @@ class sb extends Ra {
}
async function rb(a, b) {
b instanceof Qa ? b.pipe(a) : a.end(b);
return await I(a);
return await Va(a);
}
;const tb = /\/\*(?:[\s\S]+?)\*\//g, ub = /\/\/(.+)/gm;
const wb = (a = []) => {
Expand Down Expand Up @@ -833,7 +833,7 @@ const Hb = async(a, b, c = {}) => {
}
return Hb(v(qa(a), ".."), b, c);
}, Gb = async(a, b = []) => {
const c = await Va(a);
const c = await I(a);
let d, e, f, g, l;
try {
({module:d, version:e, name:f, main:g, ...l} = JSON.parse(c)), l = b.reduce((h, m) => {
Expand Down Expand Up @@ -1017,11 +1017,10 @@ const ic = async({source:a, destination:b, writable:c, debug:d, noSourceMaps:e})
const f = new hc(a);
e && (f.noSourceMaps = e);
d && (f.stopProcessing = !0);
d = x(a);
d.pipe(f);
d.on("error", g => f.emit("error", g));
[, a] = await Promise.all([Xa({source:a, ...c ? {writable:c} : {destination:b}, readable:f}), I(d), new Promise((g, l) => f.on("finish", g).on("error", l))]);
return a;
d = await I(a);
f.end(d);
await Promise.all([Xa({source:a, ...c ? {writable:c} : {destination:b}, readable:f}), new Promise((g, l) => f.on("finish", g).on("error", l))]);
return d;
};
/*
diff package https://github.com/kpdecker/jsdiff
Expand Down Expand Up @@ -1311,7 +1310,7 @@ function Ac(a = "") {
}
}
const Bc = async(a, b, c) => {
var d = await Va(a);
var d = await I(a);
d = await zc(d, {quoteProps:"dom", warn(e) {
console.warn(X(e, "yellow"));
console.warn(X(" in %s", "grey"), a);
Expand Down
15 changes: 8 additions & 7 deletions compile/depack.js
Original file line number Diff line number Diff line change
Expand Up @@ -1065,10 +1065,11 @@ const Hb = () => {
return {rules:b, markers:c};
};
class Ib {
constructor(a, b) {
constructor(a, b, c) {
this.listeners = {};
this.markers = b;
this.config = a;
this.file = c;
}
on(a, b) {
this.listeners[a] = b;
Expand All @@ -1077,15 +1078,15 @@ class Ib {
this.listeners[a](b);
}
}
const Jb = a => {
const b = Gb(), {rules:c, markers:d} = Hb(), e = new Ib(b, d);
return c.reduce((f, g) => {
var {re:k, replacement:h} = g;
return f.replace(k, h.bind(e));
const Jb = (a, b) => {
const c = Gb(), {rules:d, markers:e} = Hb(), f = new Ib(c, e, b);
return d.reduce((g, k) => {
var {re:h, replacement:l} = k;
return g.replace(h, l.bind(f));
}, a);
}, Kb = (a, b, c) => {
c = void 0 === c ? !1 : c;
const d = Jb(a);
const d = Jb(a, b);
if (c) {
return d;
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"compile-lib": "depack-dev src/depack -c -a -p -o compile -s -S",
"alamode": "compile/bin/alamode.js",
"args": "argufy -o src/bin/get-args.js",
"b": "compile/bin/alamode.js src/bin/alanode.js -o build -s"
"b": "compile/bin/alamode.js src/bin/alanode.js -o build -s",
"ba": "compile/bin/alamode.js src -o alamode -s"
},
"bin": {
"alamode": "compile/bin/alamode.js",
Expand Down
21 changes: 9 additions & 12 deletions src/lib/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import makeRules from '@a-la/markers'
import ALaImport from '@a-la/import'
import ALaExport from '@a-la/export'
import whichStream from 'which-stream'
import { collect } from 'catchment'
import { createReadStream } from 'fs'
import { read } from '@wrote/wrote'
import { basename, dirname } from 'path'
import { getMap } from './source-map'
import { getConfig } from './'
Expand Down Expand Up @@ -53,28 +52,26 @@ export const transformStream = async ({
if (noSourceMaps) alamode.noSourceMaps = noSourceMaps
if (debug) alamode['stopProcessing'] = true

const readable = createReadStream(source)
const sourceCode = await read(source)
alamode.end(sourceCode)

readable.pipe(alamode)
readable.on('error', e => alamode.emit('error', e))

const [, sourceCode] = await Promise.all([
await Promise.all([
whichStream({
source,
...(writable ? { writable } : { destination }),
readable: alamode,
}),
collect(readable),
new Promise((r, j) => alamode.on('finish', r).on('error', j)),
])
return sourceCode
}

class Context {
constructor(config, markers) {
constructor(config, markers, filename) {
this.listeners = {}
this.markers = markers
this.config = config
this.file = filename
}
on(event, listener) {
this.listeners[event] = listener
Expand All @@ -84,10 +81,10 @@ class Context {
}
}

export const transformString = (source) => {
export const transformString = (source, filename) => {
const config = getConfig()
const { rules, markers } = getRules()
const context = new Context(config, markers)
const context = new Context(config, markers, filename)

const replaced = rules.reduce((acc, { re, replacement }) => {
const newAcc = acc.replace(re, replacement.bind(context))
Expand All @@ -103,7 +100,7 @@ export const transformString = (source) => {
* @param {boolean} [noMap] Do not create source maps (used for JSX).
*/
export const syncTransform = (source, filename, noMap = false) => {
const replaced = transformString(source)
const replaced = transformString(source, filename)
if (noMap) return replaced
const file = basename(filename)
const sourceRoot = dirname(filename)
Expand Down

0 comments on commit 3d12af8

Please sign in to comment.