fix: remove unused polyvinyl functions (#42295)
This commit is contained in:
committed by
GitHub
parent
50a146224f
commit
128cb813cb
@ -12,7 +12,12 @@ import {
|
|||||||
|
|
||||||
import protect from '@freecodecamp/loop-protect';
|
import protect from '@freecodecamp/loop-protect';
|
||||||
|
|
||||||
import * as vinyl from '../../../../../utils/polyvinyl.js';
|
import {
|
||||||
|
transformContents,
|
||||||
|
transformHeadTailAndContents,
|
||||||
|
setExt,
|
||||||
|
compileHeadTail
|
||||||
|
} from '../../../../../utils/polyvinyl';
|
||||||
import createWorker from '../utils/worker-executor';
|
import createWorker from '../utils/worker-executor';
|
||||||
|
|
||||||
// the config files are created during the build, but not before linting
|
// the config files are created during the build, but not before linting
|
||||||
@ -114,7 +119,7 @@ export const testJS$JSX = overSome(testJS, testJSX);
|
|||||||
export const replaceNBSP = cond([
|
export const replaceNBSP = cond([
|
||||||
[
|
[
|
||||||
testHTML$JS$JSX,
|
testHTML$JS$JSX,
|
||||||
partial(vinyl.transformContents, contents => contents.replace(NBSPReg, ' '))
|
partial(transformContents, contents => contents.replace(NBSPReg, ' '))
|
||||||
],
|
],
|
||||||
[stubTrue, identity]
|
[stubTrue, identity]
|
||||||
]);
|
]);
|
||||||
@ -142,7 +147,7 @@ const babelTransformer = options => {
|
|||||||
await loadPresetEnv();
|
await loadPresetEnv();
|
||||||
const babelOptions = getBabelOptions(options);
|
const babelOptions = getBabelOptions(options);
|
||||||
return partial(
|
return partial(
|
||||||
vinyl.transformHeadTailAndContents,
|
transformHeadTailAndContents,
|
||||||
tryTransform(babelTransformCode(babelOptions))
|
tryTransform(babelTransformCode(babelOptions))
|
||||||
)(code);
|
)(code);
|
||||||
}
|
}
|
||||||
@ -154,10 +159,10 @@ const babelTransformer = options => {
|
|||||||
await loadPresetReact();
|
await loadPresetReact();
|
||||||
return flow(
|
return flow(
|
||||||
partial(
|
partial(
|
||||||
vinyl.transformHeadTailAndContents,
|
transformHeadTailAndContents,
|
||||||
tryTransform(babelTransformCode(babelOptionsJSX))
|
tryTransform(babelTransformCode(babelOptionsJSX))
|
||||||
),
|
),
|
||||||
partial(vinyl.setExt, 'js')
|
partial(setExt, 'js')
|
||||||
)(code);
|
)(code);
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
@ -205,19 +210,19 @@ const transformHtml = async function (file) {
|
|||||||
const div = document.createElement('div');
|
const div = document.createElement('div');
|
||||||
div.innerHTML = file.contents;
|
div.innerHTML = file.contents;
|
||||||
await Promise.all([transformSASS(div), transformScript(div)]);
|
await Promise.all([transformSASS(div), transformScript(div)]);
|
||||||
return vinyl.transformContents(() => div.innerHTML, file);
|
return transformContents(() => div.innerHTML, file);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const composeHTML = cond([
|
export const composeHTML = cond([
|
||||||
[
|
[
|
||||||
testHTML,
|
testHTML,
|
||||||
flow(
|
flow(
|
||||||
partial(vinyl.transformHeadTailAndContents, source => {
|
partial(transformHeadTailAndContents, source => {
|
||||||
const div = document.createElement('div');
|
const div = document.createElement('div');
|
||||||
div.innerHTML = source;
|
div.innerHTML = source;
|
||||||
return div.innerHTML;
|
return div.innerHTML;
|
||||||
}),
|
}),
|
||||||
partial(vinyl.compileHeadTail, '')
|
partial(compileHeadTail, '')
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
[stubTrue, identity]
|
[stubTrue, identity]
|
||||||
|
@ -1,46 +1,5 @@
|
|||||||
// originally based off of https://github.com/gulpjs/vinyl
|
// originally based off of https://github.com/gulpjs/vinyl
|
||||||
const invariant = require('invariant');
|
const invariant = require('invariant');
|
||||||
const { of, from, isObservable } = require('rxjs');
|
|
||||||
const { map, switchMap } = require('rxjs/operators');
|
|
||||||
|
|
||||||
function isPromise(value) {
|
|
||||||
return (
|
|
||||||
value &&
|
|
||||||
typeof value.subscribe !== 'function' &&
|
|
||||||
typeof value.then === 'function'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function castToObservable(maybe) {
|
|
||||||
if (isObservable(maybe)) {
|
|
||||||
return maybe;
|
|
||||||
}
|
|
||||||
if (isPromise(maybe)) {
|
|
||||||
return from(maybe);
|
|
||||||
}
|
|
||||||
return of(maybe);
|
|
||||||
}
|
|
||||||
|
|
||||||
// createFileStream(
|
|
||||||
// files: [...PolyVinyl]
|
|
||||||
// ) => Observable[...Observable[...PolyVinyl]]
|
|
||||||
function createFileStream(files = []) {
|
|
||||||
return of(from(files));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Observable::pipe(
|
|
||||||
// project(
|
|
||||||
// file: PolyVinyl
|
|
||||||
// ) => PolyVinyl|Observable[PolyVinyl]|Promise[PolyVinyl]
|
|
||||||
// ) => Observable[...Observable[...PolyVinyl]]
|
|
||||||
function pipe(project) {
|
|
||||||
const source = this;
|
|
||||||
return source.pipe(
|
|
||||||
map(files => {
|
|
||||||
return files.pipe(switchMap(file => castToObservable(project(file))));
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// interface PolyVinyl {
|
// interface PolyVinyl {
|
||||||
// source: String,
|
// source: String,
|
||||||
@ -104,12 +63,6 @@ function checkPoly(poly) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// isEmpty(poly: PolyVinyl) => Boolean, throws
|
|
||||||
function isEmpty(poly) {
|
|
||||||
checkPoly(poly);
|
|
||||||
return !!poly.contents;
|
|
||||||
}
|
|
||||||
|
|
||||||
// setContent(contents: String, poly: PolyVinyl) => PolyVinyl
|
// setContent(contents: String, poly: PolyVinyl) => PolyVinyl
|
||||||
// setContent will loose source if set
|
// setContent will loose source if set
|
||||||
function setContent(contents, poly) {
|
function setContent(contents, poly) {
|
||||||
@ -134,33 +87,6 @@ function setExt(ext, poly) {
|
|||||||
return newPoly;
|
return newPoly;
|
||||||
}
|
}
|
||||||
|
|
||||||
// setName(name: String, poly: PolyVinyl) => PolyVinyl
|
|
||||||
function setName(name, poly) {
|
|
||||||
checkPoly(poly);
|
|
||||||
const newPoly = {
|
|
||||||
...poly,
|
|
||||||
name,
|
|
||||||
path: name + '.' + poly.ext,
|
|
||||||
key: name + poly.ext
|
|
||||||
};
|
|
||||||
newPoly.history = [...poly.history, newPoly.path];
|
|
||||||
return newPoly;
|
|
||||||
}
|
|
||||||
|
|
||||||
// setError(error: Object, poly: PolyVinyl) => PolyVinyl
|
|
||||||
function setError(error, poly) {
|
|
||||||
invariant(
|
|
||||||
typeof error === 'object',
|
|
||||||
'error must be an object or null, but got %',
|
|
||||||
error
|
|
||||||
);
|
|
||||||
checkPoly(poly);
|
|
||||||
return {
|
|
||||||
...poly,
|
|
||||||
error
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// clearHeadTail(poly: PolyVinyl) => PolyVinyl
|
// clearHeadTail(poly: PolyVinyl) => PolyVinyl
|
||||||
function clearHeadTail(poly) {
|
function clearHeadTail(poly) {
|
||||||
checkPoly(poly);
|
checkPoly(poly);
|
||||||
@ -171,15 +97,6 @@ function clearHeadTail(poly) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// appendToTail (tail: String, poly: PolyVinyl) => PolyVinyl
|
|
||||||
function appendToTail(tail, poly) {
|
|
||||||
checkPoly(poly);
|
|
||||||
return {
|
|
||||||
...poly,
|
|
||||||
tail: poly.tail.concat(tail)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// compileHeadTail(padding: String, poly: PolyVinyl) => PolyVinyl
|
// compileHeadTail(padding: String, poly: PolyVinyl) => PolyVinyl
|
||||||
function compileHeadTail(padding = '', poly) {
|
function compileHeadTail(padding = '', poly) {
|
||||||
return clearHeadTail(
|
return clearHeadTail(
|
||||||
@ -217,32 +134,12 @@ function transformHeadTailAndContents(wrap, poly) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function testContents(predicate, poly) {
|
|
||||||
return !!predicate(poly.contents);
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateFileFromSpec(spec, poly) {
|
|
||||||
return setContent(poly.contents, createPoly(spec));
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
isPromise,
|
|
||||||
castToObservable,
|
|
||||||
createFileStream,
|
|
||||||
pipe,
|
|
||||||
createPoly,
|
createPoly,
|
||||||
isPoly,
|
isPoly,
|
||||||
checkPoly,
|
|
||||||
isEmpty,
|
|
||||||
setContent,
|
setContent,
|
||||||
setExt,
|
setExt,
|
||||||
setName,
|
|
||||||
setError,
|
|
||||||
clearHeadTail,
|
|
||||||
appendToTail,
|
|
||||||
compileHeadTail,
|
compileHeadTail,
|
||||||
transformContents,
|
transformContents,
|
||||||
transformHeadTailAndContents,
|
transformHeadTailAndContents
|
||||||
testContents,
|
|
||||||
updateFileFromSpec
|
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user