Skip to content

Commit 2689702

Browse files
committed
Convert to ESM: use .mjs extensions, add "type": "module"
- Rename test.js → test.mjs with ESM import syntax - Rename snapshot.cjs → snapshot.mjs with ESM import syntax - Add "type": "module" to package.json - Update npm-publish.yml require() calls for ESM compatibility
1 parent e31a9d6 commit 2689702

4 files changed

Lines changed: 25 additions & 16 deletions

File tree

.github/workflows/npm-publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ jobs:
2323
- name: Check release tag matches package version
2424
if: github.event_name == 'release'
2525
run: |
26-
package_version="$(node -p "require('./package.json').version")"
26+
package_version="$(node -e "import pkg from './package.json' with {type:'json'};console.log(pkg.default.version)")"
2727
release_version="${GITHUB_REF_NAME#v}"
2828
if [ "$package_version" != "$release_version" ]; then
2929
echo "Release tag ${GITHUB_REF_NAME} does not match package.json version ${package_version}"
3030
exit 1
3131
fi
3232
- name: Publish to npm
3333
run: |
34-
package_version="$(node -p "require('./package.json').version")"
34+
package_version="$(node -e "import pkg from './package.json' with {type:'json'};console.log(pkg.default.version)")"
3535
# Skip if this version is already published
3636
if npm view "hsluv-sass@${package_version}" version 2>/dev/null; then
3737
echo "hsluv-sass@${package_version} is already published, skipping"

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
{
22
"name": "hsluv-sass",
33
"version": "3.0.0-beta.1",
4+
"type": "module",
45
"description": "HSLuv Sass - Human friendly HSL",
56
"main": "src/_hsluv.scss",
67
"sass": "src/_hsluv.scss",
78
"directories": {
89
"test": "test"
910
},
1011
"scripts": {
11-
"test": "node test.js",
12+
"test": "node test.mjs",
1213
"lint": "prettier --check '**/*.scss'",
1314
"fix": "prettier --write '**/*.scss'"
1415
},

snapshot.cjs renamed to snapshot.mjs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
const fs = require("fs");
2-
const path = require("path");
3-
const sass = require("sass");
1+
import fs from "node:fs";
2+
import path from "node:path";
3+
import { fileURLToPath } from "node:url";
4+
import * as sass from "sass";
5+
6+
const __filename = fileURLToPath(import.meta.url);
7+
const __dirname = path.dirname(__filename);
48

59
const samples = [
610
"#1100ff",

test.js renamed to test.mjs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
var sass = require("sass");
2-
var path = require("path");
3-
var assert = require("node:assert");
1+
import * as sass from "sass";
2+
import path from "node:path";
3+
import assert from "node:assert";
4+
import { fileURLToPath } from "node:url";
45

5-
var sassFile = path.join(__dirname, "test", "hsluv-tests.scss");
6+
const __filename = fileURLToPath(import.meta.url);
7+
const __dirname = path.dirname(__filename);
68

7-
var passes = 0;
8-
var failures = 0;
9-
var currentDescribe = "";
10-
var currentIt = "";
9+
const sassFile = path.join(__dirname, "test", "hsluv-tests.scss");
1110

12-
var result = sass.compile(sassFile, {
11+
let passes = 0;
12+
let failures = 0;
13+
let currentDescribe = "";
14+
let currentIt = "";
15+
16+
const result = sass.compile(sassFile, {
1317
loadPaths: [path.join(__dirname, "test")],
1418
functions: {
1519
"_test_start_group($name)": function (args) {
@@ -22,7 +26,7 @@ var result = sass.compile(sassFile, {
2226
return sass.sassNull;
2327
},
2428
"_test_assert_result($assert, $expected, $passed)": function (args) {
25-
var passed = args[2].assertBoolean().value;
29+
const passed = args[2].assertBoolean().value;
2630
if (passed) {
2731
passes++;
2832
console.log(" \u2713 " + currentIt);

0 commit comments

Comments
 (0)