From 0e4f3eb55eff7b327ed30db7a4e76720ff94eba4 Mon Sep 17 00:00:00 2001 From: Romain Menke Date: Sat, 7 Sep 2024 17:18:26 +0200 Subject: [PATCH] fix more issues --- .rollup.mjs | 22 ---------------------- CHANGELOG.md | 6 ++++++ index.cjs | 25 +++++++------------------ index.d.ts | 26 -------------------------- index.mjs | 26 +++++++------------------- package-lock.json | 6 +++--- package.json | 6 ++---- src/lib/cssMap.js | 22 +++++----------------- 8 files changed, 30 insertions(+), 109 deletions(-) delete mode 100644 index.d.ts diff --git a/.rollup.mjs b/.rollup.mjs index acace01..6a96293 100644 --- a/.rollup.mjs +++ b/.rollup.mjs @@ -3,27 +3,5 @@ export default { output: [ { file: 'index.cjs', format: 'cjs', exports: 'default', sourcemap: false, strict: false }, { file: 'index.mjs', format: 'esm', sourcemap: false, strict: false } - ], - plugins: [ - patchBabelPluginSyntaxImportMeta(), ] } - -function patchBabelPluginSyntaxImportMeta() { - return { - name: 'patch-babel-plugin-syntax-import-meta', - renderChunk (code, chunk, options) { - const currentUrlMatch = /var url = require\('url'\);([\W\w]+)const currentURL[^\n]+\n(const currentFilename)[^\n]+/ - - const shouldTransformImportMeta = options.format === 'cjs' && currentUrlMatch.test(code) - - if (shouldTransformImportMeta) { - const updatedCode = code.replace(currentUrlMatch, '$1$2 = __filename;') - - return updatedCode - } - - return null - } - } -} diff --git a/CHANGELOG.md b/CHANGELOG.md index ae17d6d..62b7d51 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changes to PostCSS Normalize +### 12.0.0 + +- Remove TypeScript types. This package is a dual published cjs and esm and it isn't worth it, all info is in `README.md`. +- Set minimum node version to 18 +- Fix resolution of `@csstools/normalize.css` path when using ESM + ### 11.0.0 - Cleanup build dependencies diff --git a/index.cjs b/index.cjs index 5512b30..4d35a28 100644 --- a/index.cjs +++ b/index.cjs @@ -1,7 +1,7 @@ var postcssBrowserComments = require('postcss-browser-comments'); -var Module = require('module'); -var path = require('path'); - +var path = require('node:path'); +var node_module = require('node:module'); +var path$1 = require('path'); var fs = require('fs'); var postcss = require('postcss'); @@ -9,17 +9,15 @@ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentS const assign = (...objects) => Object.assign(...objects); const create = (...objects) => assign(Object.create(null), ...objects); -// get esm-compatible script metadata -const currentFilename = __filename; -const currentDirname = path.dirname(currentFilename); +const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))); // get resolved filenames for normalize.css -const normalizeCSS = resolve('@csstools/normalize.css'); +const normalizeCSS = require$1.resolve('@csstools/normalize.css'); const normalizeDir = path.dirname(normalizeCSS); const normalizeOpinionatedCSS = path.join(normalizeDir, 'opinionated.css'); // get resolved filenames for sanitize.css -const sanitizeCSS = resolve('sanitize.css'); +const sanitizeCSS = require$1.resolve('sanitize.css'); const sanitizeDir = path.dirname(sanitizeCSS); const sanitizeAssetsCSS = path.join(sanitizeDir, 'assets.css'); const sanitizeFormsCSS = path.join(sanitizeDir, 'forms.css'); @@ -57,19 +55,10 @@ const resolvedFilenamesById = create({ 'sanitize/*': [sanitizeCSS, sanitizeFormsCSS], }); -// 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) - }) -} - const cache$1 = create(); async function readFile (filename) { - filename = path.resolve(filename); + filename = path$1.resolve(filename); cache$1[filename] = cache$1[filename] || create(); diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index fed7a06..0000000 --- a/index.d.ts +++ /dev/null @@ -1,26 +0,0 @@ -import type * as PostCSS from 'postcss' - -export type PluginOptions = { - /** Determines whether multiple, duplicate insertions are allowed */ - allowDuplicates?: boolean - /** Defines an override of the project’s browserslist for this plugin. */ - browsers?: string - /** Defines whether imports from this plugin will always be inserted at the beginning of a CSS file. */ - forceImport?: boolean -} - -export type Plugin = { - (pluginOptions?: PluginOptions): { - postcssPlugin: 'postcss-normalize' - Once(root: PostCSS.Root): void - postcssImport: { - load(filename: string, importOptions: any): {} - resolve(id: string, basedir: string, importOptions: any): {} - } - } - postcss: true -} - -declare const plugin: Plugin - -export default plugin diff --git a/index.mjs b/index.mjs index 35fef0b..17709fb 100644 --- a/index.mjs +++ b/index.mjs @@ -1,25 +1,22 @@ import postcssBrowserComments from 'postcss-browser-comments'; -import Module from 'module'; -import path from 'path'; -import { URL } from 'url'; +import path from 'node:path'; +import { createRequire } from 'node:module'; +import path$1 from 'path'; import fs from 'fs'; import postcss from 'postcss'; const assign = (...objects) => Object.assign(...objects); const create = (...objects) => assign(Object.create(null), ...objects); -// get esm-compatible script metadata -const currentURL = import.meta.url; -const currentFilename = new URL(currentURL).pathname; -const currentDirname = path.dirname(currentFilename); +const require = createRequire(import.meta.url); // get resolved filenames for normalize.css -const normalizeCSS = resolve('@csstools/normalize.css'); +const normalizeCSS = require.resolve('@csstools/normalize.css'); const normalizeDir = path.dirname(normalizeCSS); const normalizeOpinionatedCSS = path.join(normalizeDir, 'opinionated.css'); // get resolved filenames for sanitize.css -const sanitizeCSS = resolve('sanitize.css'); +const sanitizeCSS = require.resolve('sanitize.css'); const sanitizeDir = path.dirname(sanitizeCSS); const sanitizeAssetsCSS = path.join(sanitizeDir, 'assets.css'); const sanitizeFormsCSS = path.join(sanitizeDir, 'forms.css'); @@ -57,19 +54,10 @@ const resolvedFilenamesById = create({ 'sanitize/*': [sanitizeCSS, sanitizeFormsCSS], }); -// 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) - }) -} - const cache$1 = create(); async function readFile (filename) { - filename = path.resolve(filename); + filename = path$1.resolve(filename); cache$1[filename] = cache$1[filename] || create(); diff --git a/package-lock.json b/package-lock.json index fd7dbb5..3493e2c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "postcss-normalize", - "version": "11.0.0", + "version": "12.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "postcss-normalize", - "version": "11.0.0", + "version": "12.0.0", "license": "CC0-1.0", "dependencies": { "@csstools/normalize.css": "*", @@ -21,7 +21,7 @@ "rollup": "^4.21.2" }, "engines": { - "node": ">= 12" + "node": ">= 18" }, "peerDependencies": { "browserslist": ">= 4", diff --git a/package.json b/package.json index 3e73f02..d815515 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "postcss-normalize", - "version": "11.0.0", + "version": "12.0.0", "description": "Use the parts of normalize.css or sanitize.css you need from your browserslist", "author": "Jonathan Neal ", "license": "CC0-1.0", @@ -9,14 +9,12 @@ "bugs": "/~https://github.com/csstools/postcss-normalize/issues", "main": "./index.cjs", "module": "./index.mjs", - "types": "./index.d.ts", "exports": { "require": "./index.cjs", "import": "./index.mjs", "default": "./index.mjs" }, "files": [ - "index.d.ts", "index.cjs", "index.mjs" ], @@ -27,7 +25,7 @@ "tape": "postcss-tape" }, "engines": { - "node": ">= 12" + "node": ">= 18" }, "peerDependencies": { "browserslist": ">= 4", diff --git a/src/lib/cssMap.js b/src/lib/cssMap.js index 443bb17..698f0a5 100644 --- a/src/lib/cssMap.js +++ b/src/lib/cssMap.js @@ -1,20 +1,17 @@ import { create } from './util' -import Module from 'module' -import path from 'path' -import { URL } from 'url' +import path from 'node:path' // get esm-compatible script metadata -const currentURL = import.meta.url -const currentFilename = new URL(currentURL).pathname -const currentDirname = path.dirname(currentFilename) +import { createRequire } from 'node:module' +const require = createRequire(import.meta.url) // get resolved filenames for normalize.css -const normalizeCSS = resolve('@csstools/normalize.css') +const normalizeCSS = require.resolve('@csstools/normalize.css') const normalizeDir = path.dirname(normalizeCSS) const normalizeOpinionatedCSS = path.join(normalizeDir, 'opinionated.css') // get resolved filenames for sanitize.css -const sanitizeCSS = resolve('sanitize.css') +const sanitizeCSS = require.resolve('sanitize.css') const sanitizeDir = path.dirname(sanitizeCSS) const sanitizeAssetsCSS = path.join(sanitizeDir, 'assets.css') const sanitizeFormsCSS = path.join(sanitizeDir, 'forms.css') @@ -51,12 +48,3 @@ export const resolvedFilenamesById = create({ 'sanitize/ui-monospace': [sanitizeCSS, sanitizeUiMonospace], 'sanitize/*': [sanitizeCSS, sanitizeFormsCSS], }) - -// 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) - }) -}