From b0e8554cced292871a67748a18926cfd02f4e840 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Mon, 28 Feb 2022 16:02:11 -0800 Subject: [PATCH] Migrate postinstall script to use modules --- extensions/package.json | 2 +- extensions/{postinstall.js => postinstall.mjs} | 13 +++++-------- 2 files changed, 6 insertions(+), 9 deletions(-) rename extensions/{postinstall.js => postinstall.mjs} (84%) diff --git a/extensions/package.json b/extensions/package.json index 33f6525fef3..84a8e079f90 100644 --- a/extensions/package.json +++ b/extensions/package.json @@ -7,7 +7,7 @@ "typescript": "4.6.2" }, "scripts": { - "postinstall": "node ./postinstall" + "postinstall": "node ./postinstall.mjs" }, "devDependencies": { "esbuild": "^0.11.12", diff --git a/extensions/postinstall.js b/extensions/postinstall.mjs similarity index 84% rename from extensions/postinstall.js rename to extensions/postinstall.mjs index da4fa3e9d04..110b9b3b476 100644 --- a/extensions/postinstall.js +++ b/extensions/postinstall.mjs @@ -2,15 +2,12 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -// @ts-check -'use strict'; +import * as fs from 'fs'; +import path from 'path'; +import { fileURLToPath } from 'url'; -const fs = require('fs'); -const path = require('path'); -const rimraf = require('rimraf'); - -const root = path.join(__dirname, 'node_modules', 'typescript'); +const root = path.join(path.dirname(fileURLToPath(import.meta.url)), 'node_modules', 'typescript'); function processRoot() { const toKeep = new Set([ @@ -21,7 +18,7 @@ function processRoot() { if (!toKeep.has(name)) { const filePath = path.join(root, name); console.log(`Removed ${filePath}`); - rimraf.sync(filePath); + fs.rmSync(filePath, { recursive: true }); } } }