Skip to content

Commit 0e4f3eb

Browse files
committed
fix more issues
1 parent 9d1a389 commit 0e4f3eb

8 files changed

+30
-109
lines changed

.rollup.mjs

-22
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,5 @@ export default {
33
output: [
44
{ file: 'index.cjs', format: 'cjs', exports: 'default', sourcemap: false, strict: false },
55
{ file: 'index.mjs', format: 'esm', sourcemap: false, strict: false }
6-
],
7-
plugins: [
8-
patchBabelPluginSyntaxImportMeta(),
96
]
107
}
11-
12-
function patchBabelPluginSyntaxImportMeta() {
13-
return {
14-
name: 'patch-babel-plugin-syntax-import-meta',
15-
renderChunk (code, chunk, options) {
16-
const currentUrlMatch = /var url = require\('url'\);([\W\w]+)const currentURL[^\n]+\n(const currentFilename)[^\n]+/
17-
18-
const shouldTransformImportMeta = options.format === 'cjs' && currentUrlMatch.test(code)
19-
20-
if (shouldTransformImportMeta) {
21-
const updatedCode = code.replace(currentUrlMatch, '$1$2 = __filename;')
22-
23-
return updatedCode
24-
}
25-
26-
return null
27-
}
28-
}
29-
}

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changes to PostCSS Normalize
22

3+
### 12.0.0
4+
5+
- Remove TypeScript types. This package is a dual published cjs and esm and it isn't worth it, all info is in `README.md`.
6+
- Set minimum node version to 18
7+
- Fix resolution of `@csstools/normalize.css` path when using ESM
8+
39
### 11.0.0
410

511
- Cleanup build dependencies

index.cjs

+7-18
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
var postcssBrowserComments = require('postcss-browser-comments');
2-
var Module = require('module');
3-
var path = require('path');
4-
2+
var path = require('node:path');
3+
var node_module = require('node:module');
4+
var path$1 = require('path');
55
var fs = require('fs');
66
var postcss = require('postcss');
77

88
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
99
const assign = (...objects) => Object.assign(...objects);
1010
const create = (...objects) => assign(Object.create(null), ...objects);
1111

12-
// get esm-compatible script metadata
13-
const currentFilename = __filename;
14-
const currentDirname = path.dirname(currentFilename);
12+
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)));
1513

1614
// get resolved filenames for normalize.css
17-
const normalizeCSS = resolve('@csstools/normalize.css');
15+
const normalizeCSS = require$1.resolve('@csstools/normalize.css');
1816
const normalizeDir = path.dirname(normalizeCSS);
1917
const normalizeOpinionatedCSS = path.join(normalizeDir, 'opinionated.css');
2018

2119
// get resolved filenames for sanitize.css
22-
const sanitizeCSS = resolve('sanitize.css');
20+
const sanitizeCSS = require$1.resolve('sanitize.css');
2321
const sanitizeDir = path.dirname(sanitizeCSS);
2422
const sanitizeAssetsCSS = path.join(sanitizeDir, 'assets.css');
2523
const sanitizeFormsCSS = path.join(sanitizeDir, 'forms.css');
@@ -57,19 +55,10 @@ const resolvedFilenamesById = create({
5755
'sanitize/*': [sanitizeCSS, sanitizeFormsCSS],
5856
});
5957

60-
// get the resolved filename of a package/module
61-
function resolve (id) {
62-
return resolve[id] = resolve[id] || Module._resolveFilename(id, {
63-
id: currentFilename,
64-
filename: currentFilename,
65-
paths: Module._nodeModulePaths(currentDirname)
66-
})
67-
}
68-
6958
const cache$1 = create();
7059

7160
async function readFile (filename) {
72-
filename = path.resolve(filename);
61+
filename = path$1.resolve(filename);
7362

7463
cache$1[filename] = cache$1[filename] || create();
7564

index.d.ts

-26
This file was deleted.

index.mjs

+7-19
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
import postcssBrowserComments from 'postcss-browser-comments';
2-
import Module from 'module';
3-
import path from 'path';
4-
import { URL } from 'url';
2+
import path from 'node:path';
3+
import { createRequire } from 'node:module';
4+
import path$1 from 'path';
55
import fs from 'fs';
66
import postcss from 'postcss';
77

88
const assign = (...objects) => Object.assign(...objects);
99
const create = (...objects) => assign(Object.create(null), ...objects);
1010

11-
// get esm-compatible script metadata
12-
const currentURL = import.meta.url;
13-
const currentFilename = new URL(currentURL).pathname;
14-
const currentDirname = path.dirname(currentFilename);
11+
const require = createRequire(import.meta.url);
1512

1613
// get resolved filenames for normalize.css
17-
const normalizeCSS = resolve('@csstools/normalize.css');
14+
const normalizeCSS = require.resolve('@csstools/normalize.css');
1815
const normalizeDir = path.dirname(normalizeCSS);
1916
const normalizeOpinionatedCSS = path.join(normalizeDir, 'opinionated.css');
2017

2118
// get resolved filenames for sanitize.css
22-
const sanitizeCSS = resolve('sanitize.css');
19+
const sanitizeCSS = require.resolve('sanitize.css');
2320
const sanitizeDir = path.dirname(sanitizeCSS);
2421
const sanitizeAssetsCSS = path.join(sanitizeDir, 'assets.css');
2522
const sanitizeFormsCSS = path.join(sanitizeDir, 'forms.css');
@@ -57,19 +54,10 @@ const resolvedFilenamesById = create({
5754
'sanitize/*': [sanitizeCSS, sanitizeFormsCSS],
5855
});
5956

60-
// get the resolved filename of a package/module
61-
function resolve (id) {
62-
return resolve[id] = resolve[id] || Module._resolveFilename(id, {
63-
id: currentFilename,
64-
filename: currentFilename,
65-
paths: Module._nodeModulePaths(currentDirname)
66-
})
67-
}
68-
6957
const cache$1 = create();
7058

7159
async function readFile (filename) {
72-
filename = path.resolve(filename);
60+
filename = path$1.resolve(filename);
7361

7462
cache$1[filename] = cache$1[filename] || create();
7563

package-lock.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "postcss-normalize",
3-
"version": "11.0.0",
3+
"version": "12.0.0",
44
"description": "Use the parts of normalize.css or sanitize.css you need from your browserslist",
55
"author": "Jonathan Neal <[email protected]>",
66
"license": "CC0-1.0",
@@ -9,14 +9,12 @@
99
"bugs": "https://github.com/csstools/postcss-normalize/issues",
1010
"main": "./index.cjs",
1111
"module": "./index.mjs",
12-
"types": "./index.d.ts",
1312
"exports": {
1413
"require": "./index.cjs",
1514
"import": "./index.mjs",
1615
"default": "./index.mjs"
1716
},
1817
"files": [
19-
"index.d.ts",
2018
"index.cjs",
2119
"index.mjs"
2220
],
@@ -27,7 +25,7 @@
2725
"tape": "postcss-tape"
2826
},
2927
"engines": {
30-
"node": ">= 12"
28+
"node": ">= 18"
3129
},
3230
"peerDependencies": {
3331
"browserslist": ">= 4",

src/lib/cssMap.js

+5-17
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
import { create } from './util'
2-
import Module from 'module'
3-
import path from 'path'
4-
import { URL } from 'url'
2+
import path from 'node:path'
53

64
// get esm-compatible script metadata
7-
const currentURL = import.meta.url
8-
const currentFilename = new URL(currentURL).pathname
9-
const currentDirname = path.dirname(currentFilename)
5+
import { createRequire } from 'node:module'
6+
const require = createRequire(import.meta.url)
107

118
// get resolved filenames for normalize.css
12-
const normalizeCSS = resolve('@csstools/normalize.css')
9+
const normalizeCSS = require.resolve('@csstools/normalize.css')
1310
const normalizeDir = path.dirname(normalizeCSS)
1411
const normalizeOpinionatedCSS = path.join(normalizeDir, 'opinionated.css')
1512

1613
// get resolved filenames for sanitize.css
17-
const sanitizeCSS = resolve('sanitize.css')
14+
const sanitizeCSS = require.resolve('sanitize.css')
1815
const sanitizeDir = path.dirname(sanitizeCSS)
1916
const sanitizeAssetsCSS = path.join(sanitizeDir, 'assets.css')
2017
const sanitizeFormsCSS = path.join(sanitizeDir, 'forms.css')
@@ -51,12 +48,3 @@ export const resolvedFilenamesById = create({
5148
'sanitize/ui-monospace': [sanitizeCSS, sanitizeUiMonospace],
5249
'sanitize/*': [sanitizeCSS, sanitizeFormsCSS],
5350
})
54-
55-
// get the resolved filename of a package/module
56-
function resolve (id) {
57-
return resolve[id] = resolve[id] || Module._resolveFilename(id, {
58-
id: currentFilename,
59-
filename: currentFilename,
60-
paths: Module._nodeModulePaths(currentDirname)
61-
})
62-
}

0 commit comments

Comments
 (0)