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: move compiled artefacts to dist folder #6272

Merged
merged 11 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ module.exports = {
},
// Example functions
{
files: ['src/functions-templates/**/*.js'],
files: ['functions-templates/**/*.js'],
rules: {
'require-await': 0,
'import/no-unresolved': 0,
Expand Down Expand Up @@ -114,6 +114,7 @@ module.exports = {
files: ['tests/**/*'],
rules: {
'require-await': 'off',
'import/no-deprecated': 'off',
},
},
{
Expand Down
6 changes: 0 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ coverage
!.vscode/launch.json
.github/styles

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

# node sdk
vendor
Expand Down
6 changes: 3 additions & 3 deletions 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.js'
import { error } from '../src/utils/command-helpers.js'
import getPackageJson from '../src/utils/get-package-json.js'
import { createMainCommand } from '../dist/commands/index.js'
import { error } from '../dist/utils/command-helpers.js'
import getPackageJson from '../dist/utils/get-package-json.js'

// 12 hours
const UPDATE_CHECK_INTERVAL = 432e5
Expand Down
14 changes: 3 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,9 @@
"files": [
"/bin",
"/npm-shrinkwrap.json",
"/scripts/postinstall.js",
"/src/**/*.js",
"/src/**/types.d.ts",
"/src/**/*.sh",
lukasholzer marked this conversation as resolved.
Show resolved Hide resolved
"/src/**/*.ps1",
"/src/functions-templates/**",
"/src/lib/templates/**",
"!/src/**/node_modules/**",
"!/src/**/*.test.js",
"!/src/**/*.ts",
"!/src/**/*.d.ts.map"
"/scripts",
"/functions-templates",
"/dist"
],
"homepage": "https://github.com/netlify/cli",
"keywords": [
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions scripts/postinstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import process from 'process'

import chalk from 'chalk'

import { createMainCommand } from '../src/commands/index.js'
import { generateAutocompletion } from '../src/lib/completion/index.js'
import { createMainCommand } from '../dist/commands/index.js'
import { generateAutocompletion } from '../dist/lib/completion/index.js'

const id = (message) => message

Expand Down
File renamed without changes.
3 changes: 1 addition & 2 deletions site/scripts/docs.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@

import { basename } from 'path'
import { env } from 'process'
import { fileURLToPath } from 'url'

import markdownMagic from 'markdown-magic'
import stripAnsi from 'strip-ansi'

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

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

Expand Down
5 changes: 2 additions & 3 deletions site/scripts/generate-command-data.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

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

const program = createMainCommand()

Expand Down
4 changes: 2 additions & 2 deletions src/commands/functions/functions-create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ const copyTemplateDir = promisify(copyTemplateDirOriginal)

const require = createRequire(import.meta.url)

const templatesDir = path.resolve(dirname(fileURLToPath(import.meta.url)), '../../functions-templates')
const templatesDir = path.resolve(dirname(fileURLToPath(import.meta.url)), '../../../functions-templates')

/**
* Ensure that there's a sub-directory in `src/functions-templates` named after
* Ensure that there's a sub-directory in `/functions-templates` named after
* each `value` property in this list.
*/
const languages = [
Expand Down
2 changes: 1 addition & 1 deletion src/lib/functions/synchronous.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@

if (acceptsHtml) {
response.setHeader('Content-Type', 'text/html')
response.end(await renderErrorTemplate(errorString, './templates/function-error.html', 'function'))
response.end(await renderErrorTemplate(errorString, '../../src/lib/templates/function-error.html', 'function'))
Dismissed Show dismissed Hide dismissed
} else {
response.end(errorString)
}
Expand Down
50 changes: 19 additions & 31 deletions src/utils/lm/install.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { appendFile, copyFile, readFile, rm, writeFile } from 'fs/promises'
import os from 'os'
import path, { dirname } from 'path'
import path, { join, sep } from 'path'
import process from 'process'
import { fileURLToPath } from 'url'

Expand Down Expand Up @@ -29,7 +29,18 @@ const SUPPORTED_PLATFORMS = {
win32: 'Windows',
}

const dirPath = dirname(fileURLToPath(import.meta.url))
const CONFIG_FILES = {
bash: '.bashrc',
zsh: '.zshrc',
fish: '.config/fish/config.fish',
}

/** The path to the scritps folder on the package root */
const scriptsPath = fileURLToPath(new URL('../../../scripts', import.meta.url))
const getHelperPath = () => getPathInHome(['helper'])
const getBinPath = () => join(getHelperPath(), 'bin')
const getGitConfigPath = () => join(getHelperPath(), 'git-config')
const getLegacyBinPath = () => join(getLegacyPathInHome(['helper', 'bin']))

// @ts-expect-error TS(7031) FIXME: Binding element 'skipInstall' implicitly has an 'a... Remove this comment to see the full error message
const getSetupStep = ({ skipInstall }) => {
Expand Down Expand Up @@ -131,7 +142,7 @@ const setupWindowsPath = async function () {
return true
}

const scriptPath = path.join(dirPath, 'scripts', 'path.ps1')
const scriptPath = join(scriptsPath, 'path.ps1')
return await execa(
'powershell',
['-ExecutionPolicy', 'unrestricted', '-windowstyle', 'hidden', '-File', scriptPath, getBinPath()],
Expand Down Expand Up @@ -160,14 +171,14 @@ Set the helper path in your environment PATH: ${getBinPath()}`
}

return await Promise.all([
await copyFile(`${dirPath}/scripts/${shell}.sh`, incFilePath),
await copyFile(join(scriptsPath, `${shell}.sh`), incFilePath),
await writeConfig(configFile, getInitContent(incFilePath)),
])
}

// @ts-expect-error TS(7006) FIXME: Parameter 'name' implicitly has an 'any' type.
const writeConfig = async function (name, initContent) {
const configPath = path.join(os.homedir(), name)
const configPath = join(os.homedir(), name)
if (!(await fileExistsAsync(configPath))) {
return
}
Expand Down Expand Up @@ -239,35 +250,13 @@ const configureGitConfig = async function () {
return writeConfig(GIT_CONFIG, getGitConfigContent(gitConfigPath))
}

const getHelperPath = function () {
return getPathInHome(['helper'])
}

const getBinPath = function () {
return path.join(getHelperPath(), 'bin')
}

const getGitConfigPath = function () {
return path.join(getHelperPath(), 'git-config')
}

const getLegacyBinPath = function () {
return path.join(getLegacyPathInHome(['helper', 'bin']))
}

const CONFIG_FILES = {
bash: '.bashrc',
zsh: '.zshrc',
fish: '.config/fish/config.fish',
}

export const getShellInfo = function () {
const shellEnv = process.env.SHELL
if (!shellEnv) {
throw new Error('Unable to detect SHELL type, make sure the variable is defined in your environment')
}

const shell = shellEnv.split(path.sep).pop()
const shell = shellEnv.split(sep).pop()
return {
shell,
incFilePath: `${getHelperPath()}/path.${shell}.inc`,
Expand Down Expand Up @@ -295,9 +284,8 @@ export const uninstall = async function () {
])
}

// @ts-expect-error TS(7006) FIXME: Parameter 'name' implicitly has an 'any' type.
const removeConfig = async function (name, toRemove) {
const configPath = path.join(os.homedir(), name)
const removeConfig = async function (name: string, toRemove: string) {
const configPath = join(os.homedir(), name)

if (!(await fileExistsAsync(configPath))) {
return
Expand Down
2 changes: 1 addition & 1 deletion src/utils/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ const initializeProxy = async function ({ configPath, distDir, env, host, imageP
const decompressedBody = await decompressResponseBody(responseBody, proxyRes.headers['content-encoding'])
const formattedBody = formatEdgeFunctionError(decompressedBody, acceptsHtml)
const errorResponse = acceptsHtml
? await renderErrorTemplate(formattedBody, './templates/function-error.html', 'edge function')
? await renderErrorTemplate(formattedBody, '../../src/lib/templates/function-error.html', 'edge function')
: formattedBody
const contentLength = Buffer.from(errorResponse, 'utf8').byteLength

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/unit/lib/account.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, test } from 'vitest'

import { supportsBackgroundFunctions } from '../../../src/lib/account.js'
import { supportsBackgroundFunctions } from '../../../dist/lib/account.js'

describe('supportsBackgroundFunctions', () => {
test(`should return false if no account`, () => {
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/lib/completion/generate-autocompletion.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import fs from 'fs'
import { Argument } from 'commander'
import { describe, expect, test, vi } from 'vitest'

import BaseCommand from '../../../../src/commands/base-command.js'
import generateAutocompletion from '../../../../src/lib/completion/generate-autocompletion.js'
import BaseCommand from '../../../../dist/commands/base-command.js'
import generateAutocompletion from '../../../../dist/lib/completion/generate-autocompletion.js'

const createTestCommand = async () => {
const program = new BaseCommand('chef')
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/lib/completion/get-autocompletion.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, describe, test } from 'vitest'

import getAutocompletion from '../../../../src/lib/completion/get-autocompletion.js'
import getAutocompletion from '../../../../dist/lib/completion/get-autocompletion.js'

const cookingFixtures = {
cook: {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/lib/edge-functions/proxy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Buffer } from 'buffer'

import { describe, expect, test } from 'vitest'

import { createSiteInfoHeader } from '../../../../src/lib/edge-functions/proxy.js'
import { createSiteInfoHeader } from '../../../../dist/lib/edge-functions/proxy.js'

describe('createSiteInfoHeader', () => {
test('builds a base64 string', () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/lib/exec-fetcher.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import process from 'process'
import { fetchLatest } from 'gh-release-fetch'
import { afterAll, afterEach, beforeAll, expect, test, vi } from 'vitest'

import { fetchLatestVersion, getArch, getExecName } from '../../../src/lib/exec-fetcher.js'
import { fetchLatestVersion, getArch, getExecName } from '../../../dist/lib/exec-fetcher.js'

vi.mock('gh-release-fetch', async () => {
const actual = await vi.importActual('gh-release-fetch')
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/lib/functions/netlify-function.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, test } from 'vitest'

import NetlifyFunction from '../../../../src/lib/functions/netlify-function.js'
import NetlifyFunction from '../../../../dist/lib/functions/netlify-function.js'

test('should return the correct function url for a NetlifyFunction object', () => {
const port = 7331
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/lib/functions/registry.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { join } from 'path'

import { describe, expect, test, vi } from 'vitest'

import { FunctionsRegistry } from '../../../../src/lib/functions/registry.js'
import { watchDebounced } from '../../../../src/utils/command-helpers.js'
import { FunctionsRegistry } from '../../../../dist/lib/functions/registry.js'
import { watchDebounced } from '../../../../dist/utils/command-helpers.js'

const duplicateFunctions = [
{
Expand Down Expand Up @@ -35,8 +35,8 @@ const duplicateFunctions = [
},
]

vi.mock('../../../../src/utils/command-helpers.js', async () => {
const helpers = await vi.importActual('../../../../src/utils/command-helpers.js')
vi.mock('../../../../dist/utils/command-helpers.js', async () => {
const helpers = await vi.importActual('../../../../dist/utils/command-helpers.js')

return {
...helpers,
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/lib/functions/runtimes/go/index.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { expect, test, vi } from 'vitest'

import { runFunctionsProxy } from '../../../../../../src/lib/functions/local-proxy.js'
import { invokeFunction } from '../../../../../../src/lib/functions/runtimes/go/index.js'
import { runFunctionsProxy } from '../../../../../../dist/lib/functions/local-proxy.js'
import { invokeFunction } from '../../../../../../dist/lib/functions/runtimes/go/index.js'

vi.mock('../../../../../../src/lib/functions/local-proxy.js', () => ({ runFunctionsProxy: vi.fn() }))
vi.mock('../../../../../../dist/lib/functions/local-proxy.js', () => ({ runFunctionsProxy: vi.fn() }))

test.each([
['body', 'thebody'],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, test, vi } from 'vitest'

import { detectNetlifyLambda } from '../../../../../../../src/lib/functions/runtimes/js/builders/netlify-lambda.js'
import { detectNetlifyLambda } from '../../../../../../../dist/lib/functions/runtimes/js/builders/netlify-lambda.js'

test(`should not find netlify-lambda from netlify-cli package.json`, async () => {
expect(await detectNetlifyLambda()).toBe(false)
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/lib/functions/runtimes/rust/index.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { expect, test, vi } from 'vitest'

import { runFunctionsProxy } from '../../../../../../src/lib/functions/local-proxy.js'
import { invokeFunction } from '../../../../../../src/lib/functions/runtimes/rust/index.js'
import { runFunctionsProxy } from '../../../../../../dist/lib/functions/local-proxy.js'
import { invokeFunction } from '../../../../../../dist/lib/functions/runtimes/rust/index.js'

vi.mock('../../../../../../src/lib/functions/local-proxy.js', () => ({ runFunctionsProxy: vi.fn() }))
vi.mock('../../../../../../dist/lib/functions/local-proxy.js', () => ({ runFunctionsProxy: vi.fn() }))

test.each([
['body', 'thebody'],
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/lib/functions/scheduled.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect, describe, test } from 'vitest'

import { buildHelpResponse } from '../../../../src/lib/functions/scheduled.js'
import { CLOCKWORK_USERAGENT } from '../../../../src/utils/functions/constants.js'
import { buildHelpResponse } from '../../../../dist/lib/functions/scheduled.js'
import { CLOCKWORK_USERAGENT } from '../../../../dist/utils/functions/constants.js'

const withAccept = (accept) =>
buildHelpResponse({
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/lib/functions/server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import express from 'express'
import fetch from 'node-fetch'
import { afterAll, beforeAll, describe, expect, test, vi } from 'vitest'

import { FunctionsRegistry } from '../../../../src/lib/functions/registry.js'
import { createHandler } from '../../../../src/lib/functions/server.js'
import StateConfig from '../../../../src/utils/state-config.js'
import { FunctionsRegistry } from '../../../../dist/lib/functions/registry.js'
import { createHandler } from '../../../../dist/lib/functions/server.js'
import StateConfig from '../../../../dist/utils/state-config.js'

vi.mock('../../../../src/utils/command-helpers.js', async () => ({
...(await vi.importActual('../../../../src/utils/command-helpers.js')),
vi.mock('../../../../dist/utils/command-helpers.js', async () => ({
...(await vi.importActual('../../../../dist/utils/command-helpers.js')),
log: () => {},
}))

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/lib/geo-location.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import nock from 'nock'
import { describe, expect, test } from 'vitest'

import { getGeoLocation, mockLocation } from '../../../src/lib/geo-location.js'
import { getGeoLocation, mockLocation } from '../../../dist/lib/geo-location.js'

describe('getGeoLocation', () => {
test('returns geolocation data from the API if `mode: "cache"`', async () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/lib/http-agent.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import ProxyServer from 'http-proxy'
import HttpsProxyAgent from 'https-proxy-agent'
import { describe, expect, test } from 'vitest'

import { tryGetAgent } from '../../../src/lib/http-agent.js'
import { tryGetAgent } from '../../../dist/lib/http-agent.js'

describe('tryGetAgent', () => {
test(`should return an empty object when there is no httpProxy`, async () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/lib/images/proxy.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, test } from 'vitest'

import { parseAllDomains, transformImageParams } from '../../../../src/lib/images/proxy.js'
import { parseAllDomains, transformImageParams } from '../../../../dist/lib/images/proxy.js'

test('should parse all domains correctly', () => {
const config = {
Expand Down
Loading
Loading