fix: remove unused polyvinyl functions (#42295)

This commit is contained in:
Oliver Eyton-Williams
2021-05-31 17:46:26 +02:00
committed by GitHub
parent 50a146224f
commit 128cb813cb
2 changed files with 14 additions and 112 deletions

View File

@ -12,7 +12,12 @@ import {
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';
// 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([
[
testHTML$JS$JSX,
partial(vinyl.transformContents, contents => contents.replace(NBSPReg, ' '))
partial(transformContents, contents => contents.replace(NBSPReg, ' '))
],
[stubTrue, identity]
]);
@ -142,7 +147,7 @@ const babelTransformer = options => {
await loadPresetEnv();
const babelOptions = getBabelOptions(options);
return partial(
vinyl.transformHeadTailAndContents,
transformHeadTailAndContents,
tryTransform(babelTransformCode(babelOptions))
)(code);
}
@ -154,10 +159,10 @@ const babelTransformer = options => {
await loadPresetReact();
return flow(
partial(
vinyl.transformHeadTailAndContents,
transformHeadTailAndContents,
tryTransform(babelTransformCode(babelOptionsJSX))
),
partial(vinyl.setExt, 'js')
partial(setExt, 'js')
)(code);
}
],
@ -205,19 +210,19 @@ const transformHtml = async function (file) {
const div = document.createElement('div');
div.innerHTML = file.contents;
await Promise.all([transformSASS(div), transformScript(div)]);
return vinyl.transformContents(() => div.innerHTML, file);
return transformContents(() => div.innerHTML, file);
};
export const composeHTML = cond([
[
testHTML,
flow(
partial(vinyl.transformHeadTailAndContents, source => {
partial(transformHeadTailAndContents, source => {
const div = document.createElement('div');
div.innerHTML = source;
return div.innerHTML;
}),
partial(vinyl.compileHeadTail, '')
partial(compileHeadTail, '')
)
],
[stubTrue, identity]

View File

@ -1,46 +1,5 @@
// originally based off of https://github.com/gulpjs/vinyl
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 {
// 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 will loose source if set
function setContent(contents, poly) {
@ -134,33 +87,6 @@ function setExt(ext, poly) {
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
function clearHeadTail(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
function compileHeadTail(padding = '', poly) {
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 = {
isPromise,
castToObservable,
createFileStream,
pipe,
createPoly,
isPoly,
checkPoly,
isEmpty,
setContent,
setExt,
setName,
setError,
clearHeadTail,
appendToTail,
compileHeadTail,
transformContents,
transformHeadTailAndContents,
testContents,
updateFileFromSpec
transformHeadTailAndContents
};