Skip to content

Commit

Permalink
feat: update project
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathantneal committed Apr 29, 2021
1 parent f690d6a commit 80668b6
Show file tree
Hide file tree
Showing 26 changed files with 428 additions and 242 deletions.
4 changes: 3 additions & 1 deletion .gitignore
@@ -1,6 +1,8 @@
dist
index.cjs*
index.mjs*
node_modules
package-lock.json
yarn.lock
*.log*
*.result.css
.*
Expand Down
20 changes: 14 additions & 6 deletions .rollup.js
@@ -1,11 +1,19 @@
import pkg from './package.json'
import babel from 'rollup-plugin-babel'

export default {
...pkg.rollup,
plugins: [patchBabelPluginSyntaxImportMeta(), ...pkg.rollup.plugins.map(plugin => require(plugin)())],
onwarn(warning, warn) {
if (warning.code !== 'UNRESOLVED_IMPORT') warn(warning)
}
input: 'src/index.js',
output: [
{ file: 'index.cjs', format: 'cjs', exports: 'default', sourcemap: true, strict: false },
{ file: 'index.mjs', format: 'esm', sourcemap: true, strict: false }
],
plugins: [
patchBabelPluginSyntaxImportMeta(),
babel({
presets: [
['@babel/env', { modules: false, targets: { node: 8 } }]
]
})
]
}

function patchBabelPluginSyntaxImportMeta () {
Expand Down
12 changes: 6 additions & 6 deletions .tape.js
Expand Up @@ -71,13 +71,13 @@ module.exports = {
source: 'import-normalize.css',
expect: 'import-normalize.expect.css',
plugin: (() => {
const postcss = require('postcss');
const postcssImport = require('postcss-import');
const postcssNormalize = require('.');
const postcss = require('postcss')
const postcssImport = require('postcss-import')
const postcssNormalize = require('.')

const plugin = postcss([ postcssImport(postcssNormalize().postcssImport()) ]);
const plugin = postcss([ postcssImport(postcssNormalize().postcssImport()) ])

return plugin;
return plugin
})()
}
};
}
5 changes: 1 addition & 4 deletions .travis.yml
Expand Up @@ -8,7 +8,4 @@ os:
- osx

node_js:
- 10

install:
- npm install --ignore-scripts
- 12
4 changes: 2 additions & 2 deletions README.md
@@ -1,7 +1,7 @@
# PostCSS Normalize [<img src="https://postcss.github.io/postcss/logo.svg" alt="PostCSS" width="90" height="90" align="right">][postcss]

[<img alt="npm version" src="https://img.shields.io/npm/v/postcss-normalize.svg" height="20">][npm-url]
[<img alt="build status" src="https://img.shields.io/travis/csstools/postcss-normalize/master.svg" height="20">][cli-url]
[<img alt="build status" src="https://img.shields.io/travis/csstools/postcss-normalize/main.svg" height="20">][cli-url]
[<img alt="support chat" src="https://img.shields.io/badge/support-chat-blue.svg" height="20">][git-url]

[PostCSS Normalize] lets you use the parts of [normalize.css] or [sanitize.css]
Expand Down Expand Up @@ -189,7 +189,7 @@ configure either with the following combinations:
@import "sanitize/*"; /* also, @import "sanitize.css/*" (sanitize + all additions) */
```

[cli-img]: https://img.shields.io/travis/csstools/postcss-normalize/master.svg
[cli-img]: https://img.shields.io/travis/csstools/postcss-normalize/main.svg
[cli-url]: https://travis-ci.org/csstools/postcss-normalize
[git-img]: https://img.shields.io/badge/support-chat-blue.svg
[git-url]: https://gitter.im/postcss/postcss
Expand Down
87 changes: 41 additions & 46 deletions package.json
Expand Up @@ -7,46 +7,46 @@
"repository": "csstools/postcss-normalize",
"homepage": "https://github.com/csstools/postcss-normalize#readme",
"bugs": "https://github.com/csstools/postcss-normalize/issues",
"main": "dist/index.cjs.js",
"module": "dist/index.esm.mjs",
"main": "index.cjs",
"module": "index.mjs",
"files": [
"dist"
"index.cjs",
"index.cjs.map",
"index.mjs",
"index.mjs.map"
],
"scripts": {
"build": "npx rollup -c .rollup.js",
"build:watch": "npx rollup -c .rollup.js --watch",
"lint": "npx eslint --cache src",
"lint:fix": "npx eslint --cache --fix",
"pretest": "npm install && npm run build",
"test": "npm run lint && npm run tape",
"tape": "npx postcss-tape"
"prepublishOnly": "npm test",
"build": "rollup --config .rollup.js --silent",
"lint": "eslint --cache .gitignore --quiet",
"test": "npm run lint && npm run build && npm run tape",
"tape": "postcss-tape"
},
"engines": {
"node": ">=10.0.0"
"node": ">= 12"
},
"peerDependencies": {
"browserslist": ">= 4",
"postcss": ">= 8"
},
"dependencies": {
"@csstools/normalize.css": "10.1.0",
"postcss-browser-comments": "^3.0.0",
"sanitize.css": "11.0.0"
"@csstools/normalize.css": "*",
"postcss-browser-comments": "^4",
"sanitize.css": "*"
},
"devDependencies": {
"@babel/core": "^7.9.0",
"@babel/plugin-syntax-import-meta": "^7.8.3",
"@babel/preset-env": "^7.9.5",
"babel-eslint": "^10.1.0",
"browserslist": "^4.16.3",
"eslint": "^6.8.0",
"postcss": "^8.2.8",
"postcss-import": "^12.0.1",
"@babel/core": "^7.13.16",
"@babel/plugin-syntax-import-meta": "^7.10.4",
"@babel/preset-env": "^7.13.15",
"browserslist": "^4.16.5",
"eslint": "^7.25.0",
"postcss": "^8.2.13",
"postcss-import": "^14.0.1",
"postcss-tape": "^6.0.1",
"pre-commit": "^1.2.2",
"rollup": "^2.6.0",
"rollup": "^2.46.0",
"rollup-plugin-babel": "^4.4.0"
},
"peerDependencies": {
"browserslist": "^4.16.3",
"postcss": "^8.2.8"
},
"babel": {
"plugins": [
"@babel/plugin-syntax-import-meta"
Expand All @@ -61,28 +61,23 @@
]
},
"eslintConfig": {
"env": {
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"parser": "babel-eslint"
},
"rollup": {
"input": "src/index.js",
"plugins": [
"rollup-plugin-babel"
"ignorePatterns": [
".tape.js"
],
"output": [
{
"file": "dist/index.cjs.js",
"format": "cjs"
},
{
"file": "dist/index.esm.js",
"format": "esm"
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module",
"ecmaFeatures": {
"modules": true
}
]
},
"rules": {
"semi": [
"error",
"never"
]
}
},
"keywords": [
"postcss",
Expand Down
20 changes: 10 additions & 10 deletions src/index.js
@@ -1,14 +1,14 @@
import { create } from './lib/util';
import postcssBrowserComments from 'postcss-browser-comments';
import postcssImportNormalize from './lib/postcssImportNormalize';
import postcssNormalize from './lib/postcssNormalize';
import { create } from './lib/util'
import postcssBrowserComments from 'postcss-browser-comments'
import postcssImportNormalize from './lib/postcssImportNormalize'
import postcssNormalize from './lib/postcssNormalize'

const plugin = opts => {
opts = create(opts);
opts = create(opts)

const commentsTransformer = postcssBrowserComments(opts).Once;
const normalizeTransformer = postcssNormalize(commentsTransformer, opts);
const postcssImportConfig = postcssImportNormalize(commentsTransformer, opts);
const commentsTransformer = postcssBrowserComments(opts).Once
const normalizeTransformer = postcssNormalize(commentsTransformer, opts)
const postcssImportConfig = postcssImportNormalize(commentsTransformer, opts)

return {
postcssPlugin: 'postcss-normalize',
Expand All @@ -19,6 +19,6 @@ const plugin = opts => {
}
}

plugin.postcss = true;
plugin.postcss = true

export default plugin;
export default plugin
32 changes: 16 additions & 16 deletions src/lib/cssMap.js
@@ -1,20 +1,20 @@
import { create } from './util';
import Module from 'module';
import path from 'path';
import { URL } from 'url';
import { create } from './util'
import Module from 'module'
import path from 'path'
import { URL } from 'url'

// get esm-compatible script metadata
const currentURL = import.meta.url;
const currentFilename = new URL(currentURL).pathname;
const currentDirname = path.dirname(currentFilename);
const currentURL = import.meta.url
const currentFilename = new URL(currentURL).pathname
const currentDirname = path.dirname(currentFilename)

// get resolved filenames for css libraries
const normalizeCSS = resolve('@csstools/normalize.css');
const normalizeOpinionatedCSS = resolve('@csstools/normalize.css/opinionated.css');
const sanitizeCSS = resolve('sanitize.css');
const sanitizeFormsCSS = resolve('sanitize.css/forms.css');
const sanitizePageCSS = resolve('sanitize.css/page.css');
const sanitizeTypographyCSS = resolve('sanitize.css/typography.css');
const normalizeCSS = resolve('@csstools/normalize.css')
const normalizeOpinionatedCSS = resolve('@csstools/normalize.css/opinionated.css')
const sanitizeCSS = resolve('sanitize.css')
const sanitizeFormsCSS = resolve('sanitize.css/forms.css')
const sanitizePageCSS = resolve('sanitize.css/page.css')
const sanitizeTypographyCSS = resolve('sanitize.css/typography.css')

// export a hashmap of css library filenames
export const parsableFilenames = create({
Expand All @@ -24,7 +24,7 @@ export const parsableFilenames = create({
[sanitizeFormsCSS]: true,
[sanitizePageCSS]: true,
[sanitizeTypographyCSS]: true
});
})

// export a hashmap of css library filenames by id
export const resolvedFilenamesById = create({
Expand All @@ -36,13 +36,13 @@ export const resolvedFilenamesById = create({
'sanitize/page': [sanitizeCSS, sanitizePageCSS],
'sanitize/typography': [sanitizeCSS, sanitizeTypographyCSS],
'sanitize/*': [sanitizeCSS, sanitizeFormsCSS, sanitizePageCSS, sanitizeTypographyCSS]
});
})

// get the resolved filename of a package/module
function resolve (id) {
return resolve[id] = resolve[id] || Module._resolveFilename(id, {
id: currentFilename,
filename: currentFilename,
paths: Module._nodeModulePaths(currentDirname)
});
})
}
10 changes: 5 additions & 5 deletions src/lib/parse.js
@@ -1,8 +1,8 @@
import { create } from './util';
import readFile from './readFile';
import postcss from 'postcss';
import { create } from './util'
import readFile from './readFile'
import postcss from 'postcss'

const cache = create(null);
const cache = create(null)

export default (filename, transformer) => readFile(filename).then(
// cache the parsed css root
Expand All @@ -18,4 +18,4 @@ export default (filename, transformer) => readFile(filename).then(
// resolve the cloned root
() => clone
)
);
)
22 changes: 11 additions & 11 deletions src/lib/postcssImportNormalize.js
@@ -1,10 +1,10 @@
import { create } from './util';
import { parsableFilenames, resolvedFilenamesById } from './cssMap';
import parse from './parse';
import readFile from './readFile';
import { create } from './util'
import { parsableFilenames, resolvedFilenamesById } from './cssMap'
import parse from './parse'
import readFile from './readFile'

export default commentsTransformer => opts => {
opts = create(opts);
opts = create(opts)

// return an postcss-import configuration
return create({
Expand All @@ -18,11 +18,11 @@ export default commentsTransformer => opts => {
// otherwise, use the override loader
? opts.load.call(null, filename, importOptions)
// otherwise, return the (conservatively cached) contents of the file
: readFile(filename);
: readFile(filename)
},
resolve (id, basedir, importOptions) {
// get the css id by removing css extensions
const cssId = id.replace(cssExtRegExp, '');
const cssId = id.replace(cssExtRegExp, '')

return cssId in resolvedFilenamesById
// return the known resolved path for the css id
Expand All @@ -31,9 +31,9 @@ export default commentsTransformer => opts => {
// otherwise, use the override resolver
? opts.resolve.call(null, id, basedir, importOptions)
// otherwise, return the id to be resolved by postcss-import
: id;
: id
}
});
};
})
}

const cssExtRegExp = /\.css\b/g;
const cssExtRegExp = /\.css\b/g

0 comments on commit 80668b6

Please sign in to comment.