Skip to content

Commit

Permalink
Prefer to use node: protocol prefix for modules
Browse files Browse the repository at this point in the history
  • Loading branch information
yhatt committed Sep 15, 2024
1 parent 77dd950 commit e9ded2e
Show file tree
Hide file tree
Showing 30 changed files with 223 additions and 123 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ module.exports = {
ecmaVersion: 'latest',
ecmaFeatures: { jsx: true },
},
plugins: ['unicorn'],
rules: {
'import-x/no-unresolved': ['error', { ignore: ['ts-key-enum'] }],
'import-x/order': ['error', { alphabetize: { order: 'asc' } }],
'unicorn/prefer-node-protocol': 'error',
},
settings: {
'import-x/resolver': {
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,18 @@
"check:audit": "yarn audit",
"check:format": "yarn -s format -c",
"check:ts": "tsc --noEmit",
"clean": "rimraf lib",
"clean": "node -e 'fs.rmSync(`lib`,{recursive:true,force:true})'",
"format": "prettier \"**/*.{css,js,jsx,json,md,mjs,scss,ts,tsx,yaml,yml}\"",
"format:write": "yarn -s format --write",
"lint:js": "ESLINT_USE_FLAT_CONFIG=false eslint --ext .js,.mjs,.jsx,.ts,.tsx --report-unused-disable-directives --cache .",
"lint:css": "stylelint \"src/**/*.{css,scss}\"",
"prepack": "npm-run-all --parallel check:* lint:* test:coverage --parallel build types",
"preversion": "run-p check:* lint:* test:coverage",
"standalone": "rimraf bin && pkg --out-path ./bin .",
"standalone": "node -e 'fs.rmSync(`bin`,{recursive:true,force:true})' && pkg --out-path ./bin .",
"standalone:pack": "node ./scripts/pack.js",
"test": "jest",
"test:coverage": "jest --coverage",
"types": "rimraf types && tsc --declaration --emitDeclarationOnly --outDir types",
"types": "node -e 'fs.rmSync(`types`,{recursive:true,force:true})' && tsc --declaration --emitDeclarationOnly --outDir types",
"version": "curl https://raw.githubusercontent.com/marp-team/actions/v1/lib/scripts/version.js | node && git add -A CHANGELOG.md",
"watch": "rollup -w -c"
},
Expand Down Expand Up @@ -106,6 +106,7 @@
"eslint-import-resolver-typescript": "^3.6.3",
"eslint-plugin-import-x": "^4.2.1",
"eslint-plugin-jest": "^28.8.3",
"eslint-plugin-unicorn": "^55.0.0",
"express": "^4.21.0",
"fast-plist": "^0.1.3",
"get-stdin": "^9.0.0",
Expand All @@ -130,7 +131,6 @@
"pptxgenjs": "^3.12.0",
"prettier": "^3.3.3",
"pug": "^3.0.3",
"rimraf": "^6.0.1",
"rollup": "^4.21.3",
"rollup-plugin-license": "^3.5.2",
"rollup-plugin-postcss": "^4.0.2",
Expand Down
9 changes: 4 additions & 5 deletions scripts/pack.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/* Pack built standalone binaries for release. */

const fs = require('fs')
const path = require('path')
const zlib = require('zlib')
const rimraf = require('rimraf')
const fs = require('node:fs')
const path = require('node:path')
const zlib = require('node:zlib')
const tar = require('tar-stream')
const ZipStream = require('zip-stream')
const { version } = require('../package.json')
Expand All @@ -24,7 +23,7 @@ const packToTarGz = (binary) => {
}

// Clean up dist directory
rimraf.sync(dist)
fs.rmSync(dist, { recursive: true, force: true })
fs.mkdirSync(dist)

// Create package for Linux (.tar.gz)
Expand Down
4 changes: 2 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'fs'
import path from 'path'
import fs from 'node:fs'
import path from 'node:path'
import chalk from 'chalk'
import { cosmiconfig, cosmiconfigSync } from 'cosmiconfig'
import { osLocale } from 'os-locale'
Expand Down
2 changes: 1 addition & 1 deletion src/converter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { URL } from 'url'
import { URL } from 'node:url'
import type { Marp, MarpOptions } from '@marp-team/marp-core'
import { Marpit, Options as MarpitOptions } from '@marp-team/marpit'
import chalk from 'chalk'
Expand Down
6 changes: 3 additions & 3 deletions src/engine.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs'
import path from 'path'
import url from 'url'
import fs from 'node:fs'
import path from 'node:path'
import url from 'node:url'
import type { Marp } from '@marp-team/marp-core'
import { Marpit } from '@marp-team/marpit'
import importFrom from 'import-from'
Expand Down
2 changes: 1 addition & 1 deletion src/engine/meta-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { URL } from 'url'
import { URL } from 'node:url'
import { Marpit } from '@marp-team/marpit'
import { warn } from '../cli'

Expand Down
10 changes: 5 additions & 5 deletions src/file.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* eslint-disable @typescript-eslint/no-namespace */
import fs from 'fs'
import os from 'os'
import path from 'path'
import * as url from 'url'
import { promisify } from 'util'
import fs from 'node:fs'
import os from 'node:os'
import path from 'node:path'
import * as url from 'node:url'
import { promisify } from 'node:util'
import getStdin from 'get-stdin'
import { globby, Options as GlobbyOptions } from 'globby'
import { tmpName } from 'tmp'
Expand Down
2 changes: 1 addition & 1 deletion src/preview.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-namespace */
import { EventEmitter } from 'events'
import { EventEmitter } from 'node:events'
import { nanoid } from 'nanoid'
import type { Page, Browser, Target } from 'puppeteer-core'
import TypedEmitter from 'typed-emitter'
Expand Down
14 changes: 7 additions & 7 deletions src/server.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* eslint-disable @typescript-eslint/no-namespace */
import EventEmitter from 'events'
import fs from 'fs'
import { Server as HttpServer } from 'http'
import path from 'path'
import querystring from 'querystring'
import url from 'url'
import { promisify } from 'util'
import EventEmitter from 'node:events'
import fs from 'node:fs'
import { Server as HttpServer } from 'node:http'
import path from 'node:path'
import querystring from 'node:querystring'
import url from 'node:url'
import { promisify } from 'node:util'
import type { Express, Request, Response } from 'express'
import serveIndex from 'serve-index'
import TypedEmitter from 'typed-emitter'
Expand Down
4 changes: 2 additions & 2 deletions src/templates/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'fs'
import path from 'path'
import fs from 'node:fs'
import path from 'node:path'
import { Element, Marpit, Options, RenderResult } from '@marp-team/marpit'
import { OutlinePage } from '../engine/pdf/outline-plugin'
import transitionPlugin, { EngineTransition } from '../engine/transition-plugin'
Expand Down
4 changes: 2 additions & 2 deletions src/theme.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-namespace */
import fs from 'fs'
import path from 'path'
import fs from 'node:fs'
import path from 'node:path'
import { Marpit } from '@marp-team/marpit'
import { isDynamicPattern } from 'globby'
import { warn } from './cli'
Expand Down
4 changes: 2 additions & 2 deletions src/utils/chrome-finder.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'fs'
import path from 'path'
import fs from 'node:fs'
import path from 'node:path'
import {
darwinFast,
linux,
Expand Down
4 changes: 2 additions & 2 deletions src/utils/edge-finder.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { accessSync, constants } from 'fs'
import path from 'path'
import { accessSync, constants } from 'node:fs'
import path from 'node:path'
import { isWSL, resolveWindowsEnvSync, resolveWSLPathToGuestSync } from './wsl'

export const findAccessiblePath = (paths: string[]): string | undefined =>
Expand Down
6 changes: 3 additions & 3 deletions src/utils/puppeteer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs'
import os from 'os'
import path from 'path'
import fs from 'node:fs'
import os from 'node:os'
import path from 'node:path'
import { nanoid } from 'nanoid'
import { launch } from 'puppeteer-core'
import macDockIcon from '../assets/mac-dock-icon.png'
Expand Down
4 changes: 2 additions & 2 deletions src/utils/wsl.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { execFile, spawnSync } from 'child_process'
import { readFileSync } from 'fs'
import { execFile, spawnSync } from 'node:child_process'
import { readFileSync } from 'node:fs'

let isWsl: number | undefined

Expand Down
4 changes: 2 additions & 2 deletions src/watcher.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-namespace */
import crypto from 'crypto'
import path from 'path'
import crypto from 'node:crypto'
import path from 'node:path'
import chokidar, { type FSWatcher } from 'chokidar'
import { getPortPromise } from 'portfinder'
import { Server as WSServer, ServerOptions } from 'ws'
Expand Down
2 changes: 1 addition & 1 deletion test/__mocks__/express.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EventEmitter } from 'events'
import { EventEmitter } from 'node:events'

const express = jest.requireActual('express')

Expand Down
4 changes: 2 additions & 2 deletions test/__mocks__/fs.ts → test/__mocks__/node:fs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { promisify } from 'util'
import { promisify } from 'node:util'

const fs = jest.requireActual('fs')
const fs = jest.requireActual('node:fs')

let writeFileMockSpy: jest.SpyInstance | undefined
let writeFilePromiseMockSpy: jest.SpyInstance | undefined
Expand Down
2 changes: 1 addition & 1 deletion test/__mocks__/path.ts → test/__mocks__/node:path.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
let mode: string | undefined

const path = jest.requireActual('path')
const path = jest.requireActual('node:path')
const pathMock: any = {
posix: () => (mode = 'posix'),
win32: () => (mode = 'win32'),
Expand Down
12 changes: 6 additions & 6 deletions test/converter.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import fs from 'fs'
import os from 'os'
import path from 'path'
import { URL } from 'url'
import { promisify } from 'util'
import fs from 'node:fs'
import os from 'node:os'
import path from 'node:path'
import { URL } from 'node:url'
import { promisify } from 'node:util'
import { Marp } from '@marp-team/marp-core'
import { Options } from '@marp-team/marpit'
import { load } from 'cheerio'
Expand All @@ -22,7 +22,7 @@ const puppeteerTimeoutMs = 60000

let mkdirSpy: jest.SpiedFunction<typeof fs.promises.mkdir>

jest.mock('fs')
jest.mock('node:fs')

beforeEach(() => {
mkdirSpy = jest.spyOn(fs.promises, 'mkdir').mockImplementation()
Expand Down
2 changes: 1 addition & 1 deletion test/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import path from 'path'
import path from 'node:path'
import getStdin from 'get-stdin'
import api, { CLIError } from '../src/index'
import * as marpCli from '../src/marp-cli'
Expand Down
8 changes: 4 additions & 4 deletions test/marp-cli.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EventEmitter } from 'events'
import fs from 'fs'
import path from 'path'
import { EventEmitter } from 'node:events'
import fs from 'node:fs'
import path from 'node:path'
import { version as coreVersion } from '@marp-team/marp-core/package.json'
import { version as marpitVersion } from '@marp-team/marpit/package.json'
import * as cosmiconfigExplorer from 'cosmiconfig/dist/Explorer' // eslint-disable-line import-x/namespace
Expand Down Expand Up @@ -39,7 +39,7 @@ const runForObservation = async (argv: string[]) => {
}

jest.mock('cosmiconfig')
jest.mock('fs')
jest.mock('node:fs')
jest.mock('../src/preview')
jest.mock('../src/watcher', () => jest.createMockFromModule('../src/watcher'))

Expand Down
4 changes: 2 additions & 2 deletions test/preview.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import path from 'path'
import path from 'node:path'
import { ConvertType } from '../src/converter'
import { CLIError } from '../src/error'
import { File, FileType } from '../src/file'
import { Preview, fileToURI } from '../src/preview'

jest.mock('path')
jest.mock('node:path')
jest.setTimeout(40000)

describe('Preview', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/theme.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import path from 'path'
import path from 'node:path'
import { Marpit } from '@marp-team/marpit'
import { ThemeSet } from '../src/theme'

Expand Down
2 changes: 1 addition & 1 deletion test/utils/edge-finder.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import path from 'path'
import path from 'node:path'
import * as edgeFinder from '../../src/utils/edge-finder'
import * as wsl from '../../src/utils/wsl'

Expand Down
6 changes: 3 additions & 3 deletions test/utils/puppeteer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-require-imports */
import os from 'os'
import path from 'path'
import os from 'node:os'
import path from 'node:path'

jest.mock('../../src/utils/chrome-finder')
jest.mock('../../src/utils/edge-finder')
Expand Down Expand Up @@ -34,7 +34,7 @@ describe('#generatePuppeteerDataDirPath', () => {
let mkdirSpy: jest.SpyInstance

beforeEach(async () => {
const { promises } = await import('fs')
const { promises } = await import('node:fs')

mkdirSpy = jest.spyOn(promises, 'mkdir')
mkdirSpy.mockImplementation(() => Promise.resolve(undefined))
Expand Down
4 changes: 2 additions & 2 deletions test/utils/wsl.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import childProcess from 'child_process'
import fs from 'fs'
import childProcess from 'node:child_process'
import fs from 'node:fs'

jest.mock('is-wsl')

Expand Down
2 changes: 1 addition & 1 deletion test/watcher.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import http from 'http'
import http from 'node:http'
import chokidar from 'chokidar'
// import * as portfinder from 'portfinder'
import { File, FileType } from '../src/file'
Expand Down
Loading

0 comments on commit e9ded2e

Please sign in to comment.