зеркало из
1
0
Форкнуть 0
Description of changes

Add `type: module` to package.json and update various build/test scripts.
This commit is contained in:
Hawk Ticehurst 2022-11-21 12:43:17 -08:00 коммит произвёл GitHub
Родитель c7c9dcba7b
Коммит c6e399c8c0
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
7 изменённых файлов: 36 добавлений и 43 удалений

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

@ -5,6 +5,7 @@
"homepage": "https://github.com/microsoft/vscode-webview-ui-toolkit#readme", "homepage": "https://github.com/microsoft/vscode-webview-ui-toolkit#readme",
"license": "MIT", "license": "MIT",
"author": "Microsoft Corporation", "author": "Microsoft Corporation",
"type": "module",
"bugs": { "bugs": {
"url": "https://github.com/microsoft/vscode-webview-ui-toolkit/issues" "url": "https://github.com/microsoft/vscode-webview-ui-toolkit/issues"
}, },

Просмотреть файл

@ -1,26 +1,26 @@
// Copyright (c) Microsoft Corporation. // Copyright (c) Microsoft Corporation.
// Licensed under the MIT License. // Licensed under the MIT License.
const fs = require('fs'); import {existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, rmdirSync, unlinkSync, writeFileSync} from 'fs';
const path = require('path'); import path from 'path';
function createDir(dir) { export function createDir(dir) {
if (!fs.existsSync(dir)) { if (!existsSync(dir)) {
fs.mkdirSync(dir); mkdirSync(dir);
} }
} }
function copyDir(source, target) { export function copyDir(source, target) {
let files = []; let files = [];
const targetFolder = path.join(target, path.basename(source)); const targetFolder = path.join(target, path.basename(source));
if (!fs.existsSync(targetFolder)) { if (!existsSync(targetFolder)) {
fs.mkdirSync(targetFolder); mkdirSync(targetFolder);
} }
if (fs.lstatSync(source).isDirectory()) { if (lstatSync(source).isDirectory()) {
files = fs.readdirSync(source); files = readdirSync(source);
files.forEach(function (file) { files.forEach(function (file) {
const curSource = path.join(source, file); const curSource = path.join(source, file);
if (fs.lstatSync(curSource).isDirectory()) { if (lstatSync(curSource).isDirectory()) {
copyDir(curSource, targetFolder); copyDir(curSource, targetFolder);
} else { } else {
copyFile(curSource, targetFolder); copyFile(curSource, targetFolder);
@ -29,14 +29,14 @@ function copyDir(source, target) {
} }
} }
function copyFile(source, target) { export function copyFile(source, target) {
let targetFile = target; let targetFile = target;
if (fs.existsSync(target)) { if (existsSync(target)) {
if (fs.lstatSync(target).isDirectory()) { if (lstatSync(target).isDirectory()) {
targetFile = path.join(target, path.basename(source)); targetFile = path.join(target, path.basename(source));
} }
} }
fs.writeFileSync(targetFile, fs.readFileSync(source)); writeFileSync(targetFile, readFileSync(source));
} }
const colors = { const colors = {
@ -48,7 +48,7 @@ const colors = {
cyan: '\x1b[36m', cyan: '\x1b[36m',
}; };
function color(opts, text) { export function color(opts, text) {
let colorString = ''; let colorString = '';
for (const opt of opts) { for (const opt of opts) {
colorString += colors[opt]; colorString += colors[opt];
@ -56,24 +56,16 @@ function color(opts, text) {
return `${colorString}${text}${colors.reset}`; return `${colorString}${text}${colors.reset}`;
} }
function delDir(path) { export function delDir(path) {
if (fs.existsSync(path) && fs.lstatSync(path).isDirectory()) { if (existsSync(path) && lstatSync(path).isDirectory()) {
fs.readdirSync(path).forEach(function (file, index) { readdirSync(path).forEach(function (file, index) {
const currPath = path + '/' + file; const currPath = path + '/' + file;
if (fs.lstatSync(currPath).isDirectory()) { if (lstatSync(currPath).isDirectory()) {
delDir(currPath); delDir(currPath);
} else { } else {
fs.unlinkSync(currPath); unlinkSync(currPath);
} }
}); });
fs.rmdirSync(path); rmdirSync(path);
} }
} }
module.exports = {
createDir,
copyDir,
copyFile,
color,
delDir,
};

Просмотреть файл

@ -1,9 +1,9 @@
// Copyright (c) Microsoft Corporation. // Copyright (c) Microsoft Corporation.
// Licensed under the MIT License. // Licensed under the MIT License.
const {copyDir, color, delDir} = require('./helpers'); import {copyDir, color, delDir} from './helpers.js';
const fsPromises = require('fs').promises; import process from 'process';
const process = require('process'); import {readFile, writeFile} from 'fs/promises';
/** /**
* Developer note: * Developer note:
@ -67,7 +67,7 @@ async function updateReactBuildImportPaths(path) {
// Read React build file and update import paths if appropriate // Read React build file and update import paths if appropriate
try { try {
const fileContents = await fsPromises.readFile(path, {encoding: 'utf8'}); const fileContents = await readFile(path, {encoding: 'utf8'});
// These regex strings rely on an assumption that they will not change // These regex strings rely on an assumption that they will not change
// If importing React components from the toolkit starts to break check here first // If importing React components from the toolkit starts to break check here first
result = fileContents.replace(/\.\.\/index/g, '../dist/index'); result = fileContents.replace(/\.\.\/index/g, '../dist/index');
@ -80,7 +80,7 @@ async function updateReactBuildImportPaths(path) {
// Overwrite React build file with any updated import paths // Overwrite React build file with any updated import paths
try { try {
await fsPromises.writeFile(path, result, {encoding: 'utf8'}); await writeFile(path, result, {encoding: 'utf8'});
} catch (err) { } catch (err) {
console.log(`${color(['red'], 'Error: Writing new React build file import paths failed.')}\n ${err}`); console.log(`${color(['red'], 'Error: Writing new React build file import paths failed.')}\n ${err}`);
process.exit(); process.exit();

Просмотреть файл

@ -1,20 +1,20 @@
// Copyright (c) Microsoft Corporation. // Copyright (c) Microsoft Corporation.
// Licensed under the MIT License. // Licensed under the MIT License.
const {createDir, copyDir, color, delDir} = require('./helpers'); import {createDir, copyDir, color, delDir} from './helpers.js';
const {exec} = require('child_process'); import {existsSync} from 'fs';
const fs = require('fs'); import {exec} from 'child_process';
const process = require('process'); import {promisify} from 'util';
const util = require('util'); import process from 'process';
const execShellCommand = util.promisify(exec); const execShellCommand = promisify(exec);
async function main() { async function main() {
// Empty print line to pretty-ify command line output // Empty print line to pretty-ify command line output
console.log(); console.log();
// Copy webview test environment locally if it does not already exist // Copy webview test environment locally if it does not already exist
if (!fs.existsSync('./test-webview')) { if (!existsSync('./test-webview')) {
try { try {
console.log(color(['dim'], 'Copying webview test environment locally...')); console.log(color(['dim'], 'Copying webview test environment locally...'));
await execShellCommand('npx degit microsoft/vscode-webview-ui-toolkit-samples/default/component-gallery test-webview'); await execShellCommand('npx degit microsoft/vscode-webview-ui-toolkit-samples/default/component-gallery test-webview');
@ -25,7 +25,7 @@ async function main() {
} }
// Install the webview test environment dependencies if they do not exist // Install the webview test environment dependencies if they do not exist
if (!fs.existsSync('./test-webview/node_modules')) { if (!existsSync('./test-webview/node_modules')) {
try { try {
console.log(color(['dim'], 'Installing webview test environment dependencies...')); console.log(color(['dim'], 'Installing webview test environment dependencies...'));
await execShellCommand('cd ./test-webview && npm install'); await execShellCommand('cd ./test-webview && npm install');