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

chore: upgrade dependencies #342

Merged
merged 5 commits into from Dec 6, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 21 additions & 21 deletions package.json
Expand Up @@ -33,40 +33,40 @@
"types": "./types/index.d.ts",
"homepage": "https://github.com/egoist/rollup-plugin-postcss#readme",
"devDependencies": {
"@babel/core": "^7.9.0",
"@babel/preset-env": "^7.9.5",
"autoprefixer": "^9.7.6",
"@babel/core": "^7.12.9",
"@babel/preset-env": "^7.12.7",
"autoprefixer": "^10.0.4",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^25.3.0",
"bili": "^4.9.0",
"babel-jest": "^26.6.3",
"bili": "^5.0.5",
"eslint-config-rem": "^4.0.0",
"fs-extra": "^9.0.0",
"jest": "^25.3.0",
"less": "^3.11.1",
"node-sass": "^4.13.1",
"postcss": "^8.0.0",
"rollup": "^2.6.1",
"stylus": "^0.54.7",
"sugarss": "^2.0.0",
"xo": "^0.29.1"
"fs-extra": "^9.0.1",
"jest": "^26.6.3",
"less": "^3.12.2",
"node-sass": "^5.0.0",
"postcss": "^8.1.14",
"rollup": "^2.34.2",
"stylus": "^0.54.8",
"sugarss": "^3.0.3",
"xo": "^0.35.0"
},
"dependencies": {
"chalk": "^4.0.0",
"chalk": "^4.1.0",
"concat-with-sourcemaps": "^1.1.0",
"cssnano": "^4.1.10",
"import-cwd": "^3.0.0",
"p-queue": "^6.3.0",
"p-queue": "^6.6.2",
"pify": "^5.0.0",
"postcss-load-config": "^2.1.0",
"postcss-modules": "^2.0.0",
"postcss-load-config": "^3.0.0",
"postcss-modules": "^4.0.0",
"promise.series": "^0.2.0",
"resolve": "^1.16.1",
"resolve": "^1.19.0",
"rollup-pluginutils": "^2.8.2",
"safe-identifier": "^0.4.1",
"safe-identifier": "^0.4.2",
"style-inject": "^0.3.0"
},
"peerDependencies": {
"postcss": "^8.0.0"
"postcss": "^8.1.14"
},
"xo": {
"extends": "rem",
Expand Down
9 changes: 4 additions & 5 deletions src/index.js
Expand Up @@ -38,6 +38,7 @@ function getRecursiveImportOrder(id, getModuleInfo, seen = new Set()) {
return result
}

/* eslint import/no-anonymous-default-export: [2, {"allowArrowFunction": true}] */
export default (options = {}) => {
const filter = createFilter(options.include, options.exclude)
const postcssPlugins = Array.isArray(options.plugins) ?
Expand Down Expand Up @@ -139,6 +140,7 @@ export default (options = {}) => {

augmentChunkHash() {
if (extracted.size === 0) return
// eslint-disable-next-line unicorn/no-reduce
const extractedValue = [...extracted].reduce((object, [key, value]) => ({
...object,
[key]: value
Expand All @@ -152,6 +154,7 @@ export default (options = {}) => {
!(options_.dir || options_.file)
) return

// eslint-disable-next-line no-warning-comments
// TODO: support `[hash]`
const dir = options_.dir || path.dirname(options_.file)
const file =
Expand All @@ -163,11 +166,7 @@ export default (options = {}) => {
const getExtracted = () => {
let fileName = `${path.basename(file, path.extname(file))}.css`
if (typeof postcssLoaderOptions.extract === 'string') {
if (path.isAbsolute(postcssLoaderOptions.extract)) {
fileName = normalizePath(path.relative(dir, postcssLoaderOptions.extract))
} else {
fileName = normalizePath(postcssLoaderOptions.extract)
}
fileName = path.isAbsolute(postcssLoaderOptions.extract) ? normalizePath(path.relative(dir, postcssLoaderOptions.extract)) : normalizePath(postcssLoaderOptions.extract)
}

const concat = new Concat(true, fileName, '\n')
Expand Down
1 change: 1 addition & 0 deletions src/less-loader.js
Expand Up @@ -2,6 +2,7 @@ import pify from 'pify'
import humanlizePath from './utils/humanlize-path'
import { loadModule } from './utils/load-module'

/* eslint import/no-anonymous-default-export: [2, {"allowObject": true}] */
export default {
name: 'less',
test: /\.less$/,
Expand Down
30 changes: 16 additions & 14 deletions src/postcss-loader.js
Expand Up @@ -52,10 +52,12 @@ function isModuleFile(file) {
return /\.module\.[a-z]{2,6}$/.test(file)
}

/* eslint import/no-anonymous-default-export: [2, {"allowObject": true}] */
export default {
name: 'postcss',
alwaysProcess: true,
// `test` option is dynamically set in ./loaders
// eslint-disable-next-line complexity
async process({ code, map }) {
const config = this.options.config ?
await loadConfig(this.id, this.options.config) :
Expand Down Expand Up @@ -126,9 +128,14 @@ export default {
if (plugins.length === 0) {
// Prevent from postcss warning:
// You did not set any plugins, parser, or stringifier. Right now, PostCSS does nothing. Pick plugins for your case on https://www.postcss.parts/ and use them in postcss.config.js
const noopPlugin = postcss.plugin('postcss-noop-plugin', () => () => {
/* noop */
})
const noopPlugin = () => {
return {
postcssPlugin: 'postcss-noop-plugin',
Once() {
}
}
}

plugins.push(noopPlugin())
}

Expand Down Expand Up @@ -201,17 +208,12 @@ export default {
}

if (!shouldExtract && shouldInject) {
if (typeof options.inject === 'function') {
output += options.inject(cssVariableName, this.id)
} else {
output += '\n' +
`import styleInject from '${styleInjectPath}';\n` +
`styleInject(${cssVariableName}${
Object.keys(options.inject).length > 0 ?
`,${JSON.stringify(options.inject)}` :
''
});`
}
output += typeof options.inject === 'function' ? options.inject(cssVariableName, this.id) : '\n' +
`import styleInject from '${styleInjectPath}';\n` +
`styleInject(${cssVariableName}${Object.keys(options.inject).length > 0 ?
`,${JSON.stringify(options.inject)}` :
''
});`
}

return {
Expand Down
3 changes: 2 additions & 1 deletion src/sass-loader.js
Expand Up @@ -21,6 +21,7 @@ const resolvePromise = pify(resolve)
// List of supported SASS modules in the order of preference
const sassModuleIds = ['node-sass', 'sass']

/* eslint import/no-anonymous-default-export: [2, {"allowObject": true}] */
export default {
name: 'sass',
test: /\.(sass|scss)$/,
Expand All @@ -29,7 +30,7 @@ export default {
const sass = loadSassOrThrow()
const render = pify(sass.render.bind(sass))
const data = this.options.data || ''
return workQueue.add(() =>
workQueue.add(() =>
render({
...this.options,
file: this.id,
Expand Down
1 change: 1 addition & 0 deletions src/stylus-loader.js
@@ -1,6 +1,7 @@
import pify from 'pify'
import { loadModule } from './utils/load-module'

/* eslint import/no-anonymous-default-export: [2, {"allowObject": true}] */
export default {
name: 'stylus',
test: /\.(styl|stylus)$/,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/load-module.js
Expand Up @@ -4,7 +4,7 @@ export function loadModule(moduleId) {
// Trying to load module normally (relative to plugin directory)
try {
return require(moduleId)
} catch (_) {
} catch {
// Ignore error
}

Expand Down
1 change: 1 addition & 0 deletions src/utils/normalize-path.js
@@ -1 +1,2 @@
/* eslint import/no-anonymous-default-export: [2, {"allowArrowFunction": true}] */
export default path => path && path.replace(/\\+/g, '/')
106 changes: 97 additions & 9 deletions test/__snapshots__/index.test.js.snap
@@ -1,5 +1,57 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`basic on-import: js code 1`] = `
"'use strict';

function styleInject(css, ref) {
if ( ref === void 0 ) ref = {};
var insertAt = ref.insertAt;

if (!css || typeof document === 'undefined') { return; }

var head = document.head || document.getElementsByTagName('head')[0];
var style = document.createElement('style');
style.type = 'text/css';

if (insertAt === 'top') {
if (head.firstChild) {
head.insertBefore(style, head.firstChild);
} else {
head.appendChild(style);
}
} else {
head.appendChild(style);
}

if (style.styleSheet) {
style.styleSheet.cssText = css;
} else {
style.appendChild(document.createTextNode(css));
}
}

var css_248z = \\"body {\\\\n color: red;\\\\n}\\\\n\\";
styleInject(css_248z);

var css_248z$1 = \\".bar {\\\\n color: red;\\\\n}\\\\n\\";
styleInject(css_248z$1);

var css_248z$2 = \\"body {\\\\n color: #f00;\\\\n background: #f00;\\\\n}\\\\n\\";
styleInject(css_248z$2);

var css_248z$3 = \\"#sidebar {\\\\n width: 30%;\\\\n background-color: #faa; }\\\\n\\";
styleInject(css_248z$3);

var css_248z$4 = \\"#header {\\\\n color: #6c94be;\\\\n}\\\\n\\";
styleInject(css_248z$4);

var css_248z$5 = \\".pcss {\\\\n color: red;\\\\n}\\\\n\\";
styleInject(css_248z$5);

console.log(css_248z, css_248z$1);
"
`;

exports[`basic postcss-config: js code 1`] = `
"'use strict';

Expand Down Expand Up @@ -191,7 +243,11 @@ exports[`extract custom-path: css map 1`] = `"{\\"version\\":3,\\"sources\\":[\\
exports[`extract custom-path: js code 1`] = `
"'use strict';

console.log(undefined, undefined);
var foo = undefined;

var bar = undefined;

console.log(foo, bar);
"
`;

Expand Down Expand Up @@ -289,7 +345,11 @@ exports[`extract relative-path: css map 1`] = `"{\\"version\\":3,\\"sources\\":[
exports[`extract relative-path: js code 1`] = `
"'use strict';

console.log(undefined, undefined);
var foo = undefined;

var bar = undefined;

console.log(foo, bar);
"
`;

Expand Down Expand Up @@ -326,7 +386,11 @@ body {
exports[`extract sourcemap-inline: js code 1`] = `
"'use strict';

console.log(undefined, undefined);
var foo = undefined;

var bar = undefined;

console.log(foo, bar);
"
`;

Expand Down Expand Up @@ -364,7 +428,11 @@ exports[`extract sourcemap-true: css map 1`] = `"{\\"version\\":3,\\"sources\\":
exports[`extract sourcemap-true: js code 1`] = `
"'use strict';

console.log(undefined, undefined);
var foo = undefined;

var bar = undefined;

console.log(foo, bar);
"
`;

Expand Down Expand Up @@ -399,7 +467,11 @@ body {
exports[`extract true: js code 1`] = `
"'use strict';

console.log(undefined, undefined);
var foo = undefined;

var bar = undefined;

console.log(foo, bar);
"
`;

Expand Down Expand Up @@ -496,7 +568,11 @@ exports[`minimize extract: css code 1`] = `".bar,body{color:red}body{background:
exports[`minimize extract: js code 1`] = `
"'use strict';

console.log(undefined, undefined);
var foo = undefined;

var bar = undefined;

console.log(foo, bar);
"
`;

Expand All @@ -508,7 +584,11 @@ exports[`minimize extract-sourcemap-inline: css code 1`] = `
exports[`minimize extract-sourcemap-inline: js code 1`] = `
"'use strict';

console.log(undefined, undefined);
var foo = undefined;

var bar = undefined;

console.log(foo, bar);
"
`;

Expand All @@ -522,7 +602,11 @@ exports[`minimize extract-sourcemap-true: css map 1`] = `"{\\"version\\":3,\\"so
exports[`minimize extract-sourcemap-true: js code 1`] = `
"'use strict';

console.log(undefined, undefined);
var foo = undefined;

var bar = undefined;

console.log(foo, bar);
"
`;

Expand Down Expand Up @@ -825,7 +909,11 @@ console.log(style$1);
exports[`onExtract 1`] = `
"'use strict';

console.log(undefined, undefined);
var foo = undefined;

var bar = undefined;

console.log(foo, bar);
"
`;

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/nested/nested.js
@@ -1,4 +1,4 @@
import './nested.css'

/* eslint import/no-anonymous-default-export: [2, {"allowLiteral": true}] */
export default 'test'
export { default as component } from './component'