Skip to content

Commit a4bf34c

Browse files
authored
migrate to ESM only prepare 6.0.0-next.1 (#233)
* migrate to ESM only prepare 6.0.0-next.1 * update
1 parent 3c1ddd6 commit a4bf34c

53 files changed

Lines changed: 176 additions & 5130 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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"request": "attach",
88
"port": 6004,
99
"sourceMaps": true,
10-
"outFiles": ["${workspaceRoot}/lib/umd/**"]
10+
"outFiles": ["${workspaceRoot}/lib/esm/**"]
1111
},
1212
{
1313
"name": "Unit Tests",
@@ -18,11 +18,11 @@
1818
"--test"
1919
],
2020
"args": [
21-
"./lib/umd/test/*.js"
21+
"./lib/esm/test/*.js"
2222
],
2323
"cwd": "${workspaceRoot}",
2424
"sourceMaps": true,
25-
"outFiles": ["${workspaceRoot}/lib/umd/**"],
25+
"outFiles": ["${workspaceRoot}/lib/esm/**"],
2626
"preLaunchTask": "npm: compile"
2727
}
2828
]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,5 @@ License
7272

7373
Copyright 2016-2023, Microsoft
7474

75-
`src/languageFacts/data/webCustomData.ts` (shipped as `lib/esm/languageFacts/data/webCustomData.ts` and `lib/umd/languageFacts/data/webCustomData.ts`)
75+
`src/languageFacts/data/webCustomData.ts` (shipped as `lib/esm/languageFacts/data/webCustomData.ts`)
7676
are built upon content from [Mozilla Developer Network](https://developer.mozilla.org/en-US/docs/Web) and distributed under CC BY-SA 2.5.

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,11 +3,15 @@
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 path from 'node:path';
8+
import os from 'node:os';
9+
import { createRequire } from 'node:module';
10+
import { fileURLToPath } from 'node:url';
911

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

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

29-
var outputPath = path.resolve(__dirname, '../src/languageFacts/data/webCustomData.ts');
33+
const outputPath = path.resolve(__dirname, '../src/languageFacts/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: 5 additions & 2 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);

build/update-jsbeautify.js

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

6-
'use strict';
6+
import path from 'node:path';
7+
import fs from 'node:fs';
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

1112
function getVersion(moduleName) {
12-
var packageJSONPath = path.join(__dirname, '..', 'node_modules', moduleName, 'package.json');
13+
const packageJSONPath = path.join(__dirname, '..', 'node_modules', moduleName, 'package.json');
1314
return readFile(packageJSONPath).then(function (content) {
1415
try {
1516
return JSON.parse(content).version;
1617
} catch (e) {
17-
return Promise.resolve(null);
18+
return null;
1819
}
1920
});
2021
}
2122

22-
function readFile(path) {
23+
function readFile(filePath) {
2324
return new Promise((s, e) => {
24-
fs.readFile(path, (err, res) => {
25+
fs.readFile(filePath, (err, res) => {
2526
if (err) {
2627
e(err);
2728
} else {
@@ -33,7 +34,7 @@ function readFile(path) {
3334
}
3435

3536
function update(moduleName, repoPath, dest, addHeader, patch) {
36-
var contentPath = path.join(__dirname, '..', 'node_modules', moduleName, repoPath);
37+
const contentPath = path.join(__dirname, '..', 'node_modules', moduleName, repoPath);
3738
console.log('Reading from ' + contentPath);
3839
return readFile(contentPath).then(function (content) {
3940
return getVersion(moduleName).then(function (version) {
@@ -62,12 +63,10 @@ function update(moduleName, repoPath, dest, addHeader, patch) {
6263
}, console.error);
6364
}
6465

65-
update('js-beautify', 'js/lib/beautify-html.js', './src/beautify/beautify-html.js', true);
66-
update('js-beautify', 'js/lib/beautify-css.js', './src/beautify/beautify-css.js', true);
6766
update('js-beautify', 'LICENSE', './src/beautify/beautify-license');
6867

6968
// ESM version
70-
update('js-beautify', 'js/lib/beautify-html.js', './src/beautify/esm/beautify-html.js', true, function (contents) {
69+
update('js-beautify', 'js/lib/beautify-html.js', './src/beautify/beautify-html.js', true, function (contents) {
7170
let topLevelFunction = '(function() {';
7271
let outputVar = 'var legacy_beautify_html';
7372
let footer = 'var style_html = legacy_beautify_html;';
@@ -84,14 +83,14 @@ update('js-beautify', 'js/lib/beautify-html.js', './src/beautify/esm/beautify-ht
8483
throw new Error(`Problem patching beautify.html for ESM: '${footer}' not found after '${outputVar}'.`);
8584
}
8685
return contents.substring(0, index1) +
87-
`import { js_beautify } from "./beautify";\nimport { css_beautify } from "./beautify-css";\n\n`
86+
`import { js_beautify } from "./beautify.js";\nimport { css_beautify } from "./beautify-css.js";\n\n`
8887
+ contents.substring(index2, index3) +
8988
`
9089
export function html_beautify(html_source, options) {
9190
return legacy_beautify_html(html_source, options, js_beautify, css_beautify);
9291
}`;
9392
});
94-
update('js-beautify', 'js/lib/beautify-css.js', './src/beautify/esm/beautify-css.js', true, function (contents) {
93+
update('js-beautify', 'js/lib/beautify-css.js', './src/beautify/beautify-css.js', true, function (contents) {
9594
let topLevelFunction = '(function() {';
9695
let outputVar = 'var legacy_beautify_css';
9796
let footer = 'var css_beautify = legacy_beautify_css;';

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: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
{
22
"name": "vscode-html-languageservice",
3-
"version": "5.6.2",
3+
"version": "6.0.0-next.1",
44
"description": "Language service for HTML",
5-
"main": "./lib/umd/htmlLanguageService.js",
6-
"typings": "./lib/umd/htmlLanguageService",
5+
"type": "module",
6+
"main": "./lib/esm/htmlLanguageService.js",
7+
"typings": "./lib/esm/htmlLanguageService",
78
"module": "./lib/esm/htmlLanguageService.js",
89
"author": "Microsoft Corporation",
910
"repository": {
@@ -31,16 +32,14 @@
3132
"vscode-uri": "^3.1.0"
3233
},
3334
"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",
36-
"compile-esm": "tsc -p ./src/tsconfig.esm.json",
37-
"watch": "tsc -w -p ./src && npm run copy-jsbeautify",
35+
"prepack": "npm run clean && npm run compile && npm run test && npm run remove-sourcemap-refs",
36+
"compile": "tsc -p ./src",
37+
"watch": "tsc -w -p ./src",
3838
"clean": "rimraf lib",
3939
"remove-sourcemap-refs": "node ./build/remove-sourcemap-refs.js",
40-
"test": "npm run compile && node --enable-source-maps --test ./lib/umd/test/*.js && npm run lint",
40+
"test": "npm run compile && node --enable-source-maps --test ./lib/esm/test/*.js && npm run lint",
4141
"lint": "eslint src/**/*.ts",
4242
"install-types-next": "npm i vscode-languageserver-types@next -f -S && npm i vscode-languageserver-textdocument@next -f -S",
43-
"copy-jsbeautify": "node ./build/copy-jsbeautify.js",
4443
"update-jsbeautify": "npm i js-beautify && node ./build/update-jsbeautify.js",
4544
"update-jsbeautify-next": "npm i js-beautify@next && node ./build/update-jsbeautify.js",
4645
"update-data": "npm i @vscode/web-custom-data -D && node ./build/generateData.js"

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;

src/beautify/beautify-html.js

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@
7474
});
7575
*/
7676

77-
(function() {
77+
import { js_beautify } from "./beautify.js";
78+
import { css_beautify } from "./beautify-css.js";
7879

79-
/* GENERATED_BUILD_OUTPUT */
8080
var legacy_beautify_html;
8181
/******/ (function() { // webpackBootstrap
8282
/******/ "use strict";
@@ -3206,39 +3206,7 @@ module.exports.TOKEN = TOKEN;
32063206
/******/
32073207
/******/ })()
32083208
;
3209-
var style_html = legacy_beautify_html;
3210-
/* Footer */
3211-
if (typeof define === "function" && define.amd) {
3212-
// Add support for AMD ( https://github.com/amdjs/amdjs-api/wiki/AMD#defineamd-property- )
3213-
define(["require", "./beautify", "./beautify-css"], function(requireamd) {
3214-
var js_beautify = requireamd("./beautify");
3215-
var css_beautify = requireamd("./beautify-css");
3216-
3217-
return {
3218-
html_beautify: function(html_source, options) {
3219-
return style_html(html_source, options, js_beautify.js_beautify, css_beautify.css_beautify);
3220-
}
3221-
};
3222-
});
3223-
} else if (typeof exports !== "undefined") {
3224-
// Add support for CommonJS. Just put this file somewhere on your require.paths
3225-
// and you will be able to `var html_beautify = require("beautify").html_beautify`.
3226-
var js_beautify = require('./beautify.js');
3227-
var css_beautify = require('./beautify-css.js');
3228-
3229-
exports.html_beautify = function(html_source, options) {
3230-
return style_html(html_source, options, js_beautify.js_beautify, css_beautify.css_beautify);
3231-
};
3232-
} else if (typeof window !== "undefined") {
3233-
// If we're running a web page and don't have either of the above, add our one global
3234-
window.html_beautify = function(html_source, options) {
3235-
return style_html(html_source, options, window.js_beautify, window.css_beautify);
3236-
};
3237-
} else if (typeof global !== "undefined") {
3238-
// If we don't even have window, try global.
3239-
global.html_beautify = function(html_source, options) {
3240-
return style_html(html_source, options, global.js_beautify, global.css_beautify);
3241-
};
3242-
}
32433209

3244-
}());
3210+
export function html_beautify(html_source, options) {
3211+
return legacy_beautify_html(html_source, options, js_beautify, css_beautify);
3212+
}

0 commit comments

Comments
 (0)