Skip to content

Commit f405566

Browse files
authored
migrate to ESM only, prepare 7.0.0-next.1 (#480)
1 parent b0ba138 commit f405566

75 files changed

Lines changed: 352 additions & 2050 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.vscode/launch.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
"runtimeArgs": [
99
"--enable-source-maps",
1010
"--test",
11-
"lib/umd/test/**/*.test.js"
11+
"lib/esm/test/**/*.test.js"
1212
],
1313
"cwd": "${workspaceRoot}",
1414
"sourceMaps": true,
1515
"outFiles": [
16-
"${workspaceRoot}/lib/umd/**"
16+
"${workspaceRoot}/lib/esm/**"
1717
],
1818
"skipFiles": [
1919
"<node_internals>/**"

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
7.0.0-next.1 / 2026-03-04
2+
=========================
3+
* BREAKING: package is now ESM-only (`"type": "module"`) and no longer publishes `lib/umd` output
4+
* BREAKING: package entrypoints now use `exports` and `types` from `lib/esm`
5+
* BREAKING: runtime and test output moved to `lib/esm` and source imports use explicit `.js` extensions for NodeNext compatibility
6+
* Build scripts in `build/` are now ESM
7+
* `update-jsbeautify` now writes the ESM formatter source directly to `src/beautify/beautify-css.js`
8+
19
6.3.0 / 2022-06-24
210
================
311
* new optional API `fileSystemProvider.getContent`

build/copy-jsbeautify.js

Lines changed: 0 additions & 23 deletions
This file was deleted.

build/generateData.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
const fs = require('fs')
7-
const path = require('path')
8-
const os = require('os')
6+
import fs from 'node:fs';
7+
import os from 'node:os';
8+
import path from 'node:path';
9+
import { createRequire } from 'node:module';
10+
import { fileURLToPath } from 'node:url';
911

12+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
13+
const require = createRequire(import.meta.url);
1014
const customData = require('@vscode/web-custom-data/data/browsers.css-data.json');
1115

1216
function toJavaScript(obj) {
@@ -21,13 +25,13 @@ const output = [
2125
' *--------------------------------------------------------------------------------------------*/',
2226
'// file generated from @vscode/web-custom-data NPM package',
2327
'',
24-
`import { ${DATA_TYPE} } from '../cssLanguageTypes';`,
28+
`import { ${DATA_TYPE} } from '../cssLanguageTypes.js';`,
2529
'',
2630
`export const cssData : ${DATA_TYPE} = ` + toJavaScript(customData) + ';'
2731
];
2832

29-
var outputPath = path.resolve(__dirname, '../src/data/webCustomData.ts');
33+
const outputPath = path.resolve(__dirname, '../src/data/webCustomData.ts');
3034
console.log('Writing to: ' + outputPath);
31-
var content = output.join(os.EOL);
35+
const content = output.join(os.EOL);
3236
fs.writeFileSync(outputPath, content);
3337
console.log('Done');

build/remove-sourcemap-refs.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
const fs = require('fs');
7-
const path = require('path');
6+
import fs from 'node:fs';
7+
import path from 'node:path';
8+
import { fileURLToPath } from 'node:url';
9+
10+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
811

912
function deleteRefs(dir) {
1013
const files = fs.readdirSync(dir);
@@ -27,6 +30,6 @@ function deleteRefs(dir) {
2730
}
2831
}
2932

30-
let location = path.join(__dirname, '..', 'lib');
33+
const location = path.join(__dirname, '..', 'lib');
3134
console.log('process ' + location);
3235
deleteRefs(location);

build/update-jsbeautify.js

Lines changed: 64 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -3,86 +3,82 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
'use strict';
6+
import fs from 'node:fs';
7+
import path from 'node:path';
8+
import { fileURLToPath } from 'node:url';
79

8-
var path = require('path');
9-
var fs = require('fs');
10+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
1011

11-
function getVersion(moduleName) {
12-
var packageJSONPath = path.join(__dirname, '..', 'node_modules', moduleName, 'package.json');
13-
return readFile(packageJSONPath).then(function (content) {
14-
try {
15-
return JSON.parse(content).version;
16-
} catch (e) {
17-
return Promise.resolve(null);
18-
}
19-
});
12+
async function getVersion(moduleName) {
13+
const packageJSONPath = path.join(__dirname, '..', 'node_modules', moduleName, 'package.json');
14+
const content = await readFile(packageJSONPath);
15+
try {
16+
return JSON.parse(content).version;
17+
} catch {
18+
return null;
19+
}
2020
}
2121

22-
function readFile(path) {
23-
return new Promise((s, e) => {
24-
fs.readFile(path, (err, res) => {
22+
function readFile(filePath) {
23+
return new Promise((resolve, reject) => {
24+
fs.readFile(filePath, (err, res) => {
2525
if (err) {
26-
e(err);
26+
reject(err);
2727
} else {
28-
s(res.toString());
28+
resolve(res.toString());
2929
}
3030
});
3131
});
32-
3332
}
3433

35-
function update(moduleName, repoPath, dest, addHeader, patch) {
36-
var contentPath = path.join(__dirname, '..', 'node_modules', moduleName, repoPath);
34+
async function update(moduleName, repoPath, dest, addHeader, patch) {
35+
const contentPath = path.join(__dirname, '..', 'node_modules', moduleName, repoPath);
3736
console.log('Reading from ' + contentPath);
38-
return readFile(contentPath).then(function (content) {
39-
return getVersion(moduleName).then(function (version) {
40-
let header = '';
41-
if (addHeader) {
42-
header = '// copied from js-beautify/' + repoPath + '\n';
43-
if (version) {
44-
header += '// version: ' + version + '\n';
45-
}
46-
}
47-
try {
48-
if (patch) {
49-
content = patch(content);
50-
}
51-
fs.writeFileSync(dest, header + content);
52-
if (version) {
53-
console.log('Updated ' + path.basename(dest) + ' (' + version + ')');
54-
} else {
55-
console.log('Updated ' + path.basename(dest));
56-
}
57-
} catch (e) {
58-
console.error(e);
37+
try {
38+
let content = await readFile(contentPath);
39+
const version = await getVersion(moduleName);
40+
let header = '';
41+
if (addHeader) {
42+
header = '// copied from js-beautify/' + repoPath + '\n';
43+
if (version) {
44+
header += '// version: ' + version + '\n';
5945
}
60-
});
61-
62-
}, console.error);
46+
}
47+
if (patch) {
48+
content = patch(content);
49+
}
50+
fs.writeFileSync(dest, header + content);
51+
if (version) {
52+
console.log('Updated ' + path.basename(dest) + ' (' + version + ')');
53+
} else {
54+
console.log('Updated ' + path.basename(dest));
55+
}
56+
} catch (e) {
57+
console.error(e);
58+
}
6359
}
6460

65-
update('js-beautify', 'js/lib/beautify-css.js', './src/beautify/beautify-css.js', true);
66-
update('js-beautify', 'LICENSE', './src/beautify/beautify-license');
67-
68-
// ESM version
69-
update('js-beautify', 'js/lib/beautify-css.js', './src/beautify/esm/beautify-css.js', true, function (contents) {
70-
let topLevelFunction = '(function() {';
71-
let outputVar = 'var legacy_beautify_css';
72-
let footer = 'var css_beautify = legacy_beautify_css;';
73-
let index1 = contents.indexOf(topLevelFunction);
74-
let index2 = contents.indexOf(outputVar, index1);
75-
let index3 = contents.indexOf(footer, index2);
76-
if (index1 === -1) {
77-
throw new Error(`Problem patching beautify.css for ESM: '${topLevelFunction}' not found.`);
78-
}
79-
if (index2 === -1) {
80-
throw new Error(`Problem patching beautify.css for ESM: '${outputVar}' not found after '${topLevelFunction}'.`);
81-
}
82-
if (index3 === -1) {
83-
throw new Error(`Problem patching beautify.css for ESM: '${footer}' not found after '${outputVar}'.`);
84-
}
85-
return contents.substring(0, index1) +
86-
contents.substring(index2, index3) +
87-
`\nexport var css_beautify = legacy_beautify_css;`;
88-
});
61+
await Promise.all([
62+
update('js-beautify', 'LICENSE', './src/beautify/beautify-license'),
63+
// Write the ESM-compatible variant directly to the main source path.
64+
update('js-beautify', 'js/lib/beautify-css.js', './src/beautify/beautify-css.js', true, (contents) => {
65+
const topLevelFunction = '(function() {';
66+
const outputVar = 'var legacy_beautify_css';
67+
const footer = 'var css_beautify = legacy_beautify_css;';
68+
const index1 = contents.indexOf(topLevelFunction);
69+
const index2 = contents.indexOf(outputVar, index1);
70+
const index3 = contents.indexOf(footer, index2);
71+
if (index1 === -1) {
72+
throw new Error(`Problem patching beautify.css for ESM: '${topLevelFunction}' not found.`);
73+
}
74+
if (index2 === -1) {
75+
throw new Error(`Problem patching beautify.css for ESM: '${outputVar}' not found after '${topLevelFunction}'.`);
76+
}
77+
if (index3 === -1) {
78+
throw new Error(`Problem patching beautify.css for ESM: '${footer}' not found after '${outputVar}'.`);
79+
}
80+
return contents.substring(0, index1) +
81+
contents.substring(index2, index3) +
82+
'\nexport var css_beautify = legacy_beautify_css;';
83+
})
84+
]);

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
{
22
"name": "vscode-css-languageservice",
3-
"version": "6.3.10",
3+
"version": "7.0.0-next.1",
44
"description": "Language service for CSS, LESS and SCSS",
5-
"main": "./lib/umd/cssLanguageService.js",
6-
"typings": "./lib/umd/cssLanguageService",
7-
"module": "./lib/esm/cssLanguageService.js",
5+
"type": "module",
6+
"exports": {
7+
".": {
8+
"types": "./lib/esm/cssLanguageService.d.ts",
9+
"import": "./lib/esm/cssLanguageService.js"
10+
}
11+
},
12+
"types": "./lib/esm/cssLanguageService.d.ts",
813
"author": "Microsoft Corporation",
914
"repository": {
1015
"type": "git",
@@ -31,19 +36,17 @@
3136
"vscode-uri": "^3.1.0"
3237
},
3338
"scripts": {
34-
"prepack": "npm run clean && npm run compile-esm && npm run test && npm run remove-sourcemap-refs",
35-
"compile": "tsc -p ./src && npm run copy-jsbeautify && npm run lint",
36-
"compile-esm": "tsc -p ./src/tsconfig.esm.json",
39+
"prepack": "npm run clean && npm run compile && npm run test && npm run remove-sourcemap-refs",
40+
"compile": "tsc -p ./src && npm run lint",
3741
"clean": "rimraf lib",
3842
"remove-sourcemap-refs": "node ./build/remove-sourcemap-refs.js",
39-
"watch": "npm run copy-jsbeautify && tsc -w -p ./src",
43+
"watch": "tsc -w -p ./src",
4044
"test": "npm run compile && npm run node-test",
41-
"node-test": "node --enable-source-maps --test lib/umd/test/**/*.test.js",
42-
"coverage": "npm run compile && npx nyc --reporter=html --reporter=text node --test lib/umd/test/**/*.test.js",
45+
"node-test": "node --enable-source-maps --test lib/esm/test/**/*.test.js",
46+
"coverage": "npm run compile && npx nyc --reporter=html --reporter=text node --test lib/esm/test/**/*.test.js",
4347
"lint": "eslint src/**/*.ts",
4448
"update-data": "npm install @vscode/web-custom-data -D && node ./build/generateData.js",
4549
"install-types-next": "npm install vscode-languageserver-types@next -f -S && npm install vscode-languageserver-textdocument@next -f -S",
46-
"copy-jsbeautify": "node ./build/copy-jsbeautify.js",
4750
"update-jsbeautify": "npm install js-beautify && node ./build/update-jsbeautify.js",
4851
"update-jsbeautify-next": "npm install js-beautify@next && node ./build/update-jsbeautify.js"
4952
}

src/beautify/beautify-css.js

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,6 @@
6464
// http://www.w3.org/TR/CSS21/syndata.html#tokenization
6565
// http://www.w3.org/TR/css3-syntax/
6666

67-
(function() {
68-
69-
/* GENERATED_BUILD_OUTPUT */
7067
var legacy_beautify_css;
7168
/******/ (function() { // webpackBootstrap
7269
/******/ "use strict";
@@ -1671,25 +1668,5 @@ module.exports.Options = Options;
16711668
/******/
16721669
/******/ })()
16731670
;
1674-
var css_beautify = legacy_beautify_css;
1675-
/* Footer */
1676-
if (typeof define === "function" && define.amd) {
1677-
// Add support for AMD ( https://github.com/amdjs/amdjs-api/wiki/AMD#defineamd-property- )
1678-
define([], function() {
1679-
return {
1680-
css_beautify: css_beautify
1681-
};
1682-
});
1683-
} else if (typeof exports !== "undefined") {
1684-
// Add support for CommonJS. Just put this file somewhere on your require.paths
1685-
// and you will be able to `var html_beautify = require("beautify").html_beautify`.
1686-
exports.css_beautify = css_beautify;
1687-
} else if (typeof window !== "undefined") {
1688-
// If we're running a web page and don't have either of the above, add our one global
1689-
window.css_beautify = css_beautify;
1690-
} else if (typeof global !== "undefined") {
1691-
// If we don't even have window, try global.
1692-
global.css_beautify = css_beautify;
1693-
}
16941671

1695-
}());
1672+
export var css_beautify = legacy_beautify_css;

0 commit comments

Comments
 (0)