Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: rename .mts to .ts #6179

Merged
merged 26 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
80c9df1
refactor: rename .mts to .ts
ericapisani Nov 16, 2023
92deca4
refactor: remove convert script
ericapisani Nov 16, 2023
21f9043
refactor: rename tests
ericapisani Nov 16, 2023
0c5fc3c
refactor: update imports and ignore some lint rules in test files
ericapisani Nov 16, 2023
0edfa5f
refactor: update lint ignore rules
ericapisani Nov 16, 2023
2e8aff0
refactor: update import
ericapisani Nov 16, 2023
c0985c2
refactor: update import
ericapisani Nov 16, 2023
0f4f2e9
refactor: update import
ericapisani Nov 16, 2023
91980f3
refactor: rename rest of the files to .js from .mjs
ericapisani Nov 16, 2023
9db5317
fix: think I accidentally introduced a typo
ericapisani Nov 16, 2023
08b138e
refactor: update command
ericapisani Nov 16, 2023
54f7c76
fix: revert unintentional changes to the lockfile
ericapisani Nov 16, 2023
44bd622
fix: docs
ericapisani Nov 16, 2023
ef1a695
refactor: revert changes to the site/ folder
ericapisani Nov 16, 2023
96ba798
refactor: missed a reference
ericapisani Nov 16, 2023
b09888c
refactor: more file extentions
ericapisani Nov 16, 2023
62c5655
refactor: another one!
ericapisani Nov 16, 2023
08f84af
test: update snapshot
ericapisani Nov 16, 2023
97b13a9
test: update snapshots (rename)
ericapisani Nov 16, 2023
b8191ab
fix: test
ericapisani Nov 16, 2023
28a99e6
Merge branch 'main' into ep/ct-296-convert-tojs
ericapisani Nov 20, 2023
fb91ff4
refactor: cleanup
ericapisani Nov 20, 2023
dc057dd
refactor: remove duplicate entry in files property
ericapisani Nov 20, 2023
885413d
Merge branch 'main' into ep/ct-296-convert-tojs
ericapisani Nov 21, 2023
8d6d21c
fix: file extension
ericapisani Nov 21, 2023
ee1770f
refactor: address CR comments
ericapisani Nov 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
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
3 changes: 1 addition & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
node_modules
src/**/*.mjs
src/**/*.d.mts
src/**/*.js
ericapisani marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4424,7 +4424,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

### Bug Fixes

* serve .mjs functions with esbuild ([#3253](https://www.github.com/netlify/cli/issues/3253)) ([c4ce183](https://www.github.com/netlify/cli/commit/c4ce183ac5b57025cbec42bb1e1f53c32b850909))
* serve .js functions with esbuild ([#3253](https://www.github.com/netlify/cli/issues/3253)) ([c4ce183](https://www.github.com/netlify/cli/commit/c4ce183ac5b57025cbec42bb1e1f53c32b850909))
ericapisani marked this conversation as resolved.
Show resolved Hide resolved

### [6.7.5](https://www.github.com/netlify/cli/compare/v6.7.4...v6.7.5) (2021-08-24)

Expand Down
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
File renamed without changes.
File renamed without changes.
ericapisani marked this conversation as resolved.
Show resolved Hide resolved
File renamed without changes.
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
Loading