mirror of
https://github.com/chenasraf/DefinitelyTyped.git
synced 2026-05-18 01:49:01 +00:00
[infra] Use ESM (#59750)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
const { Octokit } = require('@octokit/rest');
|
||||
const { paginateRest } = require('@octokit/plugin-paginate-rest');
|
||||
import { Octokit } from '@octokit/rest';
|
||||
import { paginateRest } from '@octokit/plugin-paginate-rest';
|
||||
|
||||
const CustomOctokit = Octokit.plugin(paginateRest);
|
||||
const octokit = new CustomOctokit({ auth: process.env.GITHUB_API_TOKEN });
|
||||
@@ -2,32 +2,31 @@
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
import * as fs from "fs";
|
||||
import * as path from "path";
|
||||
import JSON = require("comment-json");
|
||||
import * as fs from 'node:fs';
|
||||
import JSON from 'comment-json';
|
||||
|
||||
const home = path.join(__dirname, "..", "types");
|
||||
const home = new URL('../types/', import.meta.url);
|
||||
|
||||
for (const dirName of fs.readdirSync(home)) {
|
||||
if (dirName.startsWith(".") || dirName === "node_modules" || dirName === "scripts") {
|
||||
continue;
|
||||
}
|
||||
|
||||
const dir = path.join(home, dirName);
|
||||
const dir = new URL(`${dirName}/`, home);
|
||||
const stats = fs.lstatSync(dir);
|
||||
if (stats.isDirectory()) {
|
||||
fixTslint(dir);
|
||||
// Also do it for old versions
|
||||
for (const subdir of fs.readdirSync(dir)) {
|
||||
if (/^v\d+$/.test(subdir)) {
|
||||
fixTslint(path.join(dir, subdir));
|
||||
fixTslint(new URL(`${subdir}/`, dir));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function fixTslint(dir: string): void {
|
||||
const target = path.join(dir, 'tslint.json');
|
||||
function fixTslint(dir: URL): void {
|
||||
const target = new URL('tslint.json', dir);
|
||||
if (!fs.existsSync(target)) return;
|
||||
let json = JSON.parse(fs.readFileSync(target, 'utf-8'));
|
||||
json = fix(json);
|
||||
|
||||
@@ -3,30 +3,29 @@
|
||||
/// <reference types="node" />
|
||||
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
|
||||
const home = path.join('.', 'types');
|
||||
const home = new URL('../types/', import.meta.url);
|
||||
|
||||
for (const dirName of fs.readdirSync(home)) {
|
||||
if (dirName.startsWith('.') || dirName === 'node_modules' || dirName === 'scripts') {
|
||||
continue;
|
||||
}
|
||||
|
||||
const dir = path.join(home, dirName);
|
||||
const dir = new URL(`${dirName}/`, home);
|
||||
const stats = fs.lstatSync(dir);
|
||||
if (stats.isDirectory()) {
|
||||
fixTsconfig(dir);
|
||||
// Also do it for old versions
|
||||
for (const subdir of fs.readdirSync(dir)) {
|
||||
if (/^v\d+$/.test(subdir)) {
|
||||
fixTsconfig(path.join(dir, subdir));
|
||||
fixTsconfig(new URL(`${subdir}/`, dir));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function fixTsconfig(dir: string): void {
|
||||
const target = path.join(dir, 'tsconfig.json');
|
||||
function fixTsconfig(dir: URL): void {
|
||||
const target = new URL('tsconfig.json', dir);
|
||||
let json = JSON.parse(fs.readFileSync(target, 'utf-8'));
|
||||
json = fix(json);
|
||||
fs.writeFileSync(target, JSON.stringify(json, undefined, 4), 'utf-8');
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
// @ts-check
|
||||
const { flatMap, mapDefined } = require('@definitelytyped/utils');
|
||||
const os = require('node:os');
|
||||
const path = require("path");
|
||||
const { writeFileSync, readFileSync, readdirSync, existsSync } = require('fs-extra');
|
||||
const hp = require("@definitelytyped/header-parser");
|
||||
const { Octokit } = require('@octokit/core');
|
||||
import { flatMap, mapDefined } from "@definitelytyped/utils";
|
||||
import * as os from "node:os";
|
||||
import { writeFileSync, readFileSync, readdirSync, existsSync } from "fs-extra";
|
||||
import hp from "@definitelytyped/header-parser";
|
||||
import { Octokit } from "@octokit/core";
|
||||
|
||||
/**
|
||||
* @param {string} indexPath
|
||||
@@ -44,14 +43,14 @@ function bust(indexPath, header, ghosts) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} dir
|
||||
* @param {(subpath: string) => void} fn
|
||||
* @param {URL} dir
|
||||
* @param {(subpath: URL) => void} fn
|
||||
*/
|
||||
function recurse(dir, fn) {
|
||||
const entryPoints = readdirSync(dir, { withFileTypes: true })
|
||||
for (const subdir of entryPoints) {
|
||||
if (subdir.isDirectory() && subdir.name !== "node_modules") {
|
||||
const subpath = path.join(dir, subdir.name);
|
||||
const subpath = new URL(`${subdir.name}/`, dir);
|
||||
fn(subpath);
|
||||
recurse(subpath, fn);
|
||||
}
|
||||
@@ -62,8 +61,8 @@ function getAllHeaders() {
|
||||
/** @type {Record<string, hp.Header & { raw: string }>} */
|
||||
const headers = {};
|
||||
console.log("Reading headers...");
|
||||
recurse(path.join(__dirname, "../types"), subpath => {
|
||||
const index = path.join(subpath, "index.d.ts");
|
||||
recurse(new URL("../types/", import.meta.url), subpath => {
|
||||
const index = new URL("index.d.ts", subpath);
|
||||
if (existsSync(index)) {
|
||||
const indexContent = readFileSync(index, "utf-8");
|
||||
let parsed;
|
||||
@@ -1,8 +1,7 @@
|
||||
/// <reference lib="esnext"/>
|
||||
// Script to remove a package from DefinitelyTyped and add it to notNeededPackages.json
|
||||
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
|
||||
const typingsPackageName = process.argv[2];
|
||||
const asOfVersion = process.argv[3];
|
||||
@@ -1,5 +1,5 @@
|
||||
const fs = require('node:fs')
|
||||
const path = require('node:path');
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
for (const d of fs.readdirSync('./types')) {
|
||||
const dir = path.join('./types', d);
|
||||
const files = fs.readdirSync(dir);
|
||||
@@ -1,10 +1,8 @@
|
||||
/// <reference lib="esnext.asynciterable" />
|
||||
// Must reference esnext.asynciterable lib, since octokit uses AsyncIterable internally
|
||||
const cp = require('node:child_process');
|
||||
const os = require('node:os');
|
||||
const { AllPackages, getDefinitelyTyped, parseDefinitions, clean } = require('@definitelytyped/definitions-parser');
|
||||
const { loggerWithErrors } = require('@definitelytyped/utils');
|
||||
const { writeFile } = require('fs-extra');
|
||||
import * as cp from 'node:child_process';
|
||||
import * as os from 'node:os';
|
||||
import { AllPackages, getDefinitelyTyped, parseDefinitions, clean } from '@definitelytyped/definitions-parser';
|
||||
import { loggerWithErrors } from '@definitelytyped/utils';
|
||||
import { writeFile } from 'fs-extra';
|
||||
|
||||
async function main() {
|
||||
const options = { definitelyTypedPath: '.', progress: false, parseInParallel: true };
|
||||
@@ -1,8 +1,8 @@
|
||||
import * as fs from "fs";
|
||||
import * as fs from "node:fs";
|
||||
import * as stringify from "json-stable-stringify";
|
||||
import * as path from "path";
|
||||
import * as path from "node:path";
|
||||
import { Configuration as Config, ILinterOptions, Linter, LintResult } from "tslint";
|
||||
import * as ts from "typescript";
|
||||
import ts from "typescript";
|
||||
import { isExternalDependency } from "./dependencies";
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import * as path from "path";
|
||||
import * as ts from "typescript";
|
||||
import * as path from "node:path";
|
||||
import ts from "typescript";
|
||||
|
||||
export function isExternalDependency(file: ts.SourceFile, dirPath: string, program: ts.Program): boolean {
|
||||
return !startsWithDirectory(file.fileName, dirPath) || program.isSourceFileFromExternalLibrary(file);
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
// configuration with your rule, then register a disabler function for your rule
|
||||
// (check `disableRules` function below), then run this script with your rule as argument.
|
||||
|
||||
import * as fs from "fs";
|
||||
import * as path from "path";
|
||||
import * as fs from "node:fs";
|
||||
import * as path from "node:path";
|
||||
import { Configuration as Config } from "tslint";
|
||||
import * as yargs from "yargs";
|
||||
import { normalizePath } from "./dependencies";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as cp from "child_process";
|
||||
import * as fs from "fs";
|
||||
import * as path from "path";
|
||||
import * as cp from "node:child_process";
|
||||
import * as fs from "node:fs";
|
||||
import * as path from "node:path";
|
||||
import { Configuration as Config, ILinterOptions, IRuleFailureJson, RuleFailure } from "tslint";
|
||||
|
||||
import { ignoredRules } from "./ignoredRules";
|
||||
|
||||
Reference in New Issue
Block a user