Skip to content

Commit

Permalink
fix more issues
Browse files Browse the repository at this point in the history
  • Loading branch information
romainmenke committed Sep 7, 2024
1 parent 9d1a389 commit 0e4f3eb
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 109 deletions.
22 changes: 0 additions & 22 deletions .rollup.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
25 changes: 7 additions & 18 deletions index.cjs
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
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');

var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
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');
Expand Down Expand Up @@ -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();

Expand Down
26 changes: 0 additions & 26 deletions index.d.ts

This file was deleted.

26 changes: 7 additions & 19 deletions index.mjs
Original file line number Diff line number Diff line change
@@ -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');
Expand Down Expand Up @@ -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();

Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
"license": "CC0-1.0",
Expand All @@ -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"
],
Expand All @@ -27,7 +25,7 @@
"tape": "postcss-tape"
},
"engines": {
"node": ">= 12"
"node": ">= 18"
},
"peerDependencies": {
"browserslist": ">= 4",
Expand Down
22 changes: 5 additions & 17 deletions src/lib/cssMap.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down Expand Up @@ -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)
})
}

0 comments on commit 0e4f3eb

Please sign in to comment.