Skip to content

Commit

Permalink
refactor: rename .mts to .ts (#6179)
Browse files Browse the repository at this point in the history
* refactor: rename .mts to .ts

Rename .mjs to .js

* refactor: remove convert script

Update package.json

* refactor: rename tests

* refactor: update imports and ignore some lint rules in test files

* refactor: update lint ignore rules

* refactor: update import

* refactor: update import

* refactor: update import

* refactor: rename rest of the files to .js from .mjs

* fix: think I accidentally introduced a typo

* refactor: update command

* fix: revert unintentional changes to the lockfile

* fix: docs

* refactor: revert changes to the site/ folder

* refactor: missed a reference

* refactor: more file extentions

* refactor: another one!

* test: update snapshot

* test: update snapshots (rename)

* fix: test

* refactor: cleanup

* refactor: remove duplicate entry in files property

* fix: file extension

* refactor: address CR comments
  • Loading branch information
ericapisani authored Nov 21, 2023
1 parent e5c33a0 commit 5eb2133
Show file tree
Hide file tree
Showing 401 changed files with 976 additions and 957 deletions.
10 changes: 5 additions & 5 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ module.exports = {
},
},
},
// .mjs files in this folder are compiled from TS
ignorePatterns: ['src/**/*.mjs'],
// .js files in this folder are compiled from TS
ignorePatterns: ['src/**/*.js'],
rules: {
'workspace/no-process-cwd': 'error',
// Those rules from @netlify/eslint-config-node are currently disabled
Expand Down Expand Up @@ -89,7 +89,7 @@ module.exports = {
},
},
{
files: ['bin/**/*.mjs'],
files: ['bin/**/*.js'],
parserOptions: {
ecmaVersion: '2020',
sourceType: 'module',
Expand All @@ -106,7 +106,7 @@ module.exports = {
{
name: 'chalk',
message:
'Please use the safe chalk import that handles colors for json output. `import { chalk } from "src/utils/command-helpers.mjs"`',
'Please use the safe chalk import that handles colors for json output. `import { chalk } from "src/utils/command-helpers.js"`',
},
],
},
Expand All @@ -118,7 +118,7 @@ module.exports = {
},
},
{
files: ['*.mts'],
files: ['*.ts'],
rules: {
// Pure ES modules with TypeScript require using `.js` instead of `.ts`
// in imports
Expand Down
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ coverage
.github/styles

# compiled files
src/**/*.mjs
!src/functions-templates/**/*.mjs
src/**/*.d.mts
src/**/*.d.mts.map
src/**/*.js
!src/functions-templates/**/*.js
src/**/*.d.ts
src/**/*.d.ts.map
tsconfig.tsbuildinfo

# node sdk
Expand Down
4 changes: 2 additions & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
node_modules
src/**/*.mjs
src/**/*.d.mts
src/**/*.js
src/**/*.d.ts
12 changes: 6 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Running some integration tests requires an active Netlify account to create a li

You can either provide a
[Netlify Auth Token](https://docs.netlify.com/cli/get-started/#obtain-a-token-in-the-netlify-ui) (through the
`NETLIFY_AUTH_TOKEN` environment variable) or login via `./bin/run.mjs login` before running the tests.
`NETLIFY_AUTH_TOKEN` environment variable) or login via `./bin/run.js login` before running the tests.

The tests don’t count towards Netlify build minutes since they build a site locally and deploy it using the API.

Expand Down Expand Up @@ -80,13 +80,13 @@ Alternatively, you can set up your IDE to integrate with Prettier and ESLint for
To run the CLI locally:

```bash
./bin/run.mjs [command]
./bin/run.js [command]
```

or (`DEBUG=true` enables printing stack traces when errors are thrown):

```bash
DEBUG=true ./bin/run.mjs [command]
DEBUG=true ./bin/run.js [command]
```

### Architecture
Expand Down Expand Up @@ -150,13 +150,13 @@ We also test for a few other things:
To run a single test file you can do:

```
npm exec vitest -- run tests/unit/tests/unit/lib/account.test.mjs
npm exec vitest -- run tests/unit/tests/unit/lib/account.test.js
```

To run a single test you can either use `test.only` inside the test file and ran the above command or run this:

```
npm exec vitest -- run tests/unit/tests/unit/lib/account.test.mjs -t 'test name'
npm exec vitest -- run tests/unit/tests/unit/lib/account.test.js -t 'test name'
```

Some of the tests actually start the CLI in a subprocess and therefore sometimes underlying errors are not visible in
Expand All @@ -168,7 +168,7 @@ When `DEBUG_TESTS` is set the vitest reporter will be set to `tap` so the test o
output.

```
DEBUG_TESTS=true npm exec vitest -- run tests/unit/tests/unit/lib/account.test.mjs -t 'test name'
DEBUG_TESTS=true npm exec vitest -- run tests/unit/tests/unit/lib/account.test.js -t 'test name'
```

### Lint docs per Netlify style guide
Expand Down
6 changes: 3 additions & 3 deletions bin/run.mjs → bin/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { argv } from 'process'

import updateNotifier from 'update-notifier'

import { createMainCommand } from '../src/commands/index.mjs'
import { error } from '../src/utils/command-helpers.mjs'
import getPackageJson from '../src/utils/get-package-json.mjs'
import { createMainCommand } from '../src/commands/index.js'
import { error } from '../src/utils/command-helpers.js'
import getPackageJson from '../src/utils/get-package-json.js'

// 12 hours
const UPDATE_CHECK_INTERVAL = 432e5
Expand Down
2 changes: 1 addition & 1 deletion e2e/install.e2e.mjs → e2e/install.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { fileURLToPath } from 'url'
import execa from 'execa'
import { expect, test } from 'vitest'

import { packageManagerConfig, packageManagerExists } from './utils.mjs'
import { packageManagerConfig, packageManagerExists } from './utils.js'

const { version } = JSON.parse(readFileSync(fileURLToPath(new URL('../package.json', import.meta.url)), 'utf-8'))

Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 14 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,17 @@
"files": [
"/bin",
"/npm-shrinkwrap.json",
"/scripts/postinstall.mjs",
"/scripts/postinstall.js",
"/src/**/*.js",
"/src/**/*.mjs",
"/src/**/types.d.ts",
"/src/**/*.sh",
"/src/**/*.ps1",
"/src/functions-templates/**",
"/src/lib/templates/**",
"!/src/**/node_modules/**",
"!/src/**/*.test.js",
"!/src/**/*.mts",
"!/src/**/*.d.mts.map"
"!/src/**/*.ts",
"!/src/**/*.d.ts.map"
],
"homepage": "https://github.com/netlify/cli",
"keywords": [
Expand All @@ -33,24 +32,24 @@
"license": "MIT",
"repository": "https://github.com/netlify/cli",
"bin": {
"ntl": "./bin/run.mjs",
"netlify": "./bin/run.mjs"
"ntl": "./bin/run.js",
"netlify": "./bin/run.js"
},
"bugs": {
"url": "https://github.com/netlify/cli/issues"
},
"scripts": {
"prepare": "is-ci || husky install node_modules/@netlify/eslint-config-node/.husky/",
"start": "node ./bin/run.mjs",
"start": "node ./bin/run.js",
"build": "tsc",
"dev": "tsc --watch",
"test": "run-s format test:dev",
"format": "run-s format:check-fix:*",
"format:ci": "run-s format:check:*",
"format:check-fix:lint": "run-e format:check:lint format:fix:lint",
"format:check-fix:lint": "run-s format:check:lint format:fix:lint",
"format:check:lint": "cross-env-shell eslint $npm_package_config_eslint",
"format:fix:lint": "cross-env-shell eslint --fix $npm_package_config_eslint",
"format:check-fix:prettier": "run-e format:check:prettier format:fix:prettier",
"format:check-fix:prettier": "run-s format:check:prettier format:fix:prettier",
"format:check:prettier": "cross-env-shell prettier --check $npm_package_config_prettier --ignore-path .prettierignore",
"format:fix:prettier": "cross-env-shell prettier --write $npm_package_config_prettier --ignore-path .prettierignore",
"test:dev": "run-s certs test:init:* test:dev:*",
Expand All @@ -62,16 +61,16 @@
"test:dev:vitest": "vitest run tests/unit/ && vitest run tests/integration",
"test:ci:vitest:unit": "vitest run --coverage tests/unit/",
"test:ci:vitest:integration": "vitest run --coverage tests/integration/",
"test:affected": "node ./tools/affected-test.mjs",
"e2e": "node ./tools/e2e/run.mjs",
"test:affected": "node ./tools/affected-test.js",
"e2e": "node ./tools/e2e/run.js",
"docs": "node ./site/scripts/docs.mjs",
"watch": "c8 --reporter=lcov vitest --watch",
"site:build": "run-s site:build:*",
"site:build:install": "cd site && npm install --no-audit",
"site:build:assets": "cd site && npm run build",
"postinstall-pack": "node ./scripts/postinstall.mjs",
"postinstall": "npm run build && node ./scripts/postinstall.mjs",
"prepublishOnly": "node ./scripts/prepare-for-publish.mjs",
"postinstall-pack": "node ./scripts/postinstall.js",
"postinstall": "npm run build && node ./scripts/postinstall.js",
"prepublishOnly": "node ./scripts/prepare-for-publish.js",
"certs": "openssl req -x509 -out localhost.crt -keyout localhost.key -newkey rsa:2048 -nodes -sha256 -subj \"/CN=localhost\" -extensions EXT -config certconf"
},
"config": {
Expand Down Expand Up @@ -228,7 +227,7 @@
},
"ava": {
"files": [
"tools/**/*.test.mjs",
"tools/**/*.test.js",
"tests/**/*.test.cjs"
]
}
Expand Down
7 changes: 3 additions & 4 deletions scripts/postinstall.mjs → scripts/postinstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import process from 'process'

import chalk from 'chalk'

import { createMainCommand } from '../src/commands/index.mjs'
// TODO: use destructuring again once the imported file is esm
import { generateAutocompletion } from '../src/lib/completion/index.mjs'
import { createMainCommand } from '../src/commands/index.js'
import { generateAutocompletion } from '../src/lib/completion/index.js'

const id = (message) => message

Expand All @@ -28,7 +27,7 @@ const format = (message, styles) => {
const postInstall = async () => {
// yarn plug and play seems to have an issue with reading an esm file by building up the cache.
// as yarn pnp analyzes everything inside the postinstall
// yarn pnp executes it out of a .yarn folder .yarn/unplugged/netlify-cli-file-fb026a3a6d/node_modules/netlify-cli/scripts/postinstall.mjs
// yarn pnp executes it out of a .yarn folder .yarn/unplugged/netlify-cli-file-fb026a3a6d/node_modules/netlify-cli/scripts/postinstall.js
if (!process.argv[1].includes('.yarn')) {
// create or update the autocompletion definition
const program = createMainCommand()
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion site/scripts/docs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { fileURLToPath } from 'url'
import markdownMagic from 'markdown-magic'
import stripAnsi from 'strip-ansi'

import { normalizeBackslash } from '../../src/lib/path.mjs'
import { normalizeBackslash } from '../../src/lib/path.js'

import { generateCommandData } from './generate-command-data.mjs'

Expand Down
8 changes: 4 additions & 4 deletions site/scripts/generate-command-data.mjs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@

import { createMainCommand } from '../../src/commands/index.mjs'
import { sortOptions } from '../../src/utils/command-helpers.mjs'
import { createMainCommand } from '../../src/commands/index.js'
import { sortOptions } from '../../src/utils/command-helpers.js'

const program = createMainCommand()

/** @type {Array<import('../../src/commands/base-command.mjs').default>} */
/** @type {Array<import('../../src/commands/base-command.js').default>} */
// @ts-ignore typecast needed
const commands = program.commands.sort((cmdA, cmdB) => cmdA.name().localeCompare(cmdB.name()))

/**
*
* @param {import('../../src/commands/base-command.mjs').default} command
* @param {import('../../src/commands/base-command.js').default} command
*/
const parseCommand = function (command) {
const args = command._args.map(({ _name: name, description }) => ({
Expand Down
4 changes: 2 additions & 2 deletions site/watch.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { join } from 'path'

import sane from 'sane'

import { docs } from './config.mjs'
import { ensureFilePathAsync } from './fs.mjs'
import { docs } from './config.js'
import { ensureFilePathAsync } from './fs.js'

const watcher = sane(docs.srcPath, { glob: ['**/*.md'] })

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { ADDON_VALIDATION, prepareAddonCommand } from '../../utils/addons/prepare.mjs'
import { exit, log } from '../../utils/command-helpers.mjs'
import openBrowser from '../../utils/open-browser.mjs'

import { ADDON_VALIDATION, prepareAddonCommand } from '../../utils/addons/prepare.js'
import { exit, log } from '../../utils/command-helpers.js'
import openBrowser from '../../utils/open-browser.js'

/**
* The addons:auth command
* @param {string} addonName
* @param {import('commander').OptionValues} options
* @param {import('../base-command.mjs').default} command
* @param {import('../base-command.js').default} command
* @returns {Promise<boolean>}
*/
// @ts-expect-error TS(7006) FIXME: Parameter 'addonName' implicitly has an 'any' type... Remove this comment to see the full error message
Expand Down Expand Up @@ -34,7 +35,7 @@ const addonsAuth = async (addonName, options, command) => {

/**
* Creates the `netlify addons:auth` command
* @param {import('../base-command.mjs').default} program
* @param {import('../base-command.js').default} program
* @returns
*/
// @ts-expect-error TS(7006) FIXME: Parameter 'program' implicitly has an 'any' type.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import inquirer from 'inquirer'
import isEmpty from 'lodash/isEmpty.js'

import compare from '../../utils/addons/compare.mjs'
import diffValues from '../../utils/addons/diffs/index.mjs'
import { ADDON_VALIDATION, prepareAddonCommand } from '../../utils/addons/prepare.mjs'
import generatePrompts from '../../utils/addons/prompts.mjs'
import { renderConfigValues } from '../../utils/addons/render.mjs'
import { missingConfigValues, requiredConfigValues, updateConfigValues } from '../../utils/addons/validation.mjs'
import { chalk, error, log } from '../../utils/command-helpers.mjs'
import { parseRawFlags } from '../../utils/parse-raw-flags.mjs'
import compare from '../../utils/addons/compare.js'
import diffValues from '../../utils/addons/diffs/index.js'
import { ADDON_VALIDATION, prepareAddonCommand } from '../../utils/addons/prepare.js'
import generatePrompts from '../../utils/addons/prompts.js'
import { renderConfigValues } from '../../utils/addons/render.js'
import { missingConfigValues, requiredConfigValues, updateConfigValues } from '../../utils/addons/validation.js'
import { chalk, error, log } from '../../utils/command-helpers.js'
import { parseRawFlags } from '../../utils/parse-raw-flags.js'

// @ts-expect-error TS(7031) FIXME: Binding element 'addonName' implicitly has an 'any... Remove this comment to see the full error message
const update = async function ({ addonName, api, currentConfig, instanceId, newConfig, siteId }) {
Expand Down Expand Up @@ -42,7 +42,7 @@ const update = async function ({ addonName, api, currentConfig, instanceId, newC
* The addons:config command
* @param {string} addonName
* @param {import('commander').OptionValues} options
* @param {import('../base-command.mjs').default} command
* @param {import('../base-command.js').default} command
* @returns {Promise<boolean>}
*/
// @ts-expect-error TS(7006) FIXME: Parameter 'addonName' implicitly has an 'any' type... Remove this comment to see the full error message
Expand Down Expand Up @@ -167,7 +167,7 @@ const addonsConfig = async (addonName, options, command) => {

/**
* Creates the `netlify addons:config` command
* @param {import('../base-command.mjs').default} program
* @param {import('../base-command.js').default} program
* @returns
*/
// @ts-expect-error TS(7006) FIXME: Parameter 'program' implicitly has an 'any' type.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import inquirer from 'inquirer'
import isEmpty from 'lodash/isEmpty.js'

import { ADDON_VALIDATION, prepareAddonCommand } from '../../utils/addons/prepare.mjs'
import generatePrompts from '../../utils/addons/prompts.mjs'
import { renderConfigValues, renderMissingValues } from '../../utils/addons/render.mjs'
import { missingConfigValues, requiredConfigValues, updateConfigValues } from '../../utils/addons/validation.mjs'
import { chalk, error, log } from '../../utils/command-helpers.mjs'
import { parseRawFlags } from '../../utils/parse-raw-flags.mjs'
import { ADDON_VALIDATION, prepareAddonCommand } from '../../utils/addons/prepare.js'
import generatePrompts from '../../utils/addons/prompts.js'
import { renderConfigValues, renderMissingValues } from '../../utils/addons/render.js'
import { missingConfigValues, requiredConfigValues, updateConfigValues } from '../../utils/addons/validation.js'
import { chalk, error, log } from '../../utils/command-helpers.js'
import { parseRawFlags } from '../../utils/parse-raw-flags.js'

// @ts-expect-error TS(7031) FIXME: Binding element 'addonName' implicitly has an 'any... Remove this comment to see the full error message
const createAddon = async ({ addonName, api, config, siteData, siteId }) => {
Expand All @@ -31,7 +31,7 @@ const createAddon = async ({ addonName, api, config, siteData, siteId }) => {
* The addons:create command
* @param {string} addonName
* @param {import('commander').OptionValues} options
* @param {import('../base-command.mjs').default} command
* @param {import('../base-command.js').default} command
* @returns {Promise<boolean>}
*/
// @ts-expect-error TS(7006) FIXME: Parameter 'addonName' implicitly has an 'any' type... Remove this comment to see the full error message
Expand Down Expand Up @@ -114,7 +114,7 @@ const addonsCreate = async (addonName, options, command) => {

/**
* Creates the `netlify addons:create` command
* @param {import('../base-command.mjs').default} program
* @param {import('../base-command.js').default} program
* @returns
*/
// @ts-expect-error TS(7006) FIXME: Parameter 'program' implicitly has an 'any' type.
Expand Down
Loading

1 comment on commit 5eb2133

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📊 Benchmark results

  • Dependency count: 1,396
  • Package size: 404 MB
  • Number of ts-expect-error directives: 0

Please sign in to comment.