-
Notifications
You must be signed in to change notification settings - Fork 76
fix: improve types and remove path-exists dependency #6552
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
base: main
Are you sure you want to change the base?
Changes from all commits
5a0c01a
dbca3d9
c7181ca
8138bce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
import { readFile, rm } from 'fs/promises' | ||
import { readFile, rm, access } from 'fs/promises' | ||
import { normalize, resolve } from 'path' | ||
import { fileURLToPath } from 'url' | ||
|
||
import cpy from 'cpy' | ||
import { pathExists } from 'path-exists' | ||
import sortOn from 'sort-on' | ||
import { expect, test, vi } from 'vitest' | ||
|
||
|
@@ -13,6 +12,15 @@ import { getDist, createDist } from './helpers/main.js' | |
|
||
const FIXTURES_DIR = fileURLToPath(new URL('fixtures', import.meta.url)) | ||
|
||
const pathExists = async (path: string): Promise<boolean> => { | ||
try { | ||
await access(path) | ||
return true | ||
} catch { | ||
return false | ||
} | ||
} | ||
|
||
test('Should copy a source file to a dist directory', async () => { | ||
const dist = await getDist() | ||
try { | ||
|
@@ -45,7 +53,8 @@ test('Should throw when source is undefined', async () => { | |
test('Should throw when source is empty array', async () => { | ||
const dist = await getDist() | ||
try { | ||
await expect(() => add([] as any, dist)).rejects.toThrow() | ||
// @ts-expect-error testing invalid input | ||
await expect(() => add([], dist)).rejects.toThrow() | ||
} finally { | ||
await rm(dist, { force: true, recursive: true }) | ||
} | ||
|
@@ -101,13 +110,26 @@ test('Should overwrite dist file if it already exists', async () => { | |
}) | ||
|
||
test('Should allow "fail" option to customize failures', async () => { | ||
const fail = vi.fn() as any | ||
const fail = vi.fn() | ||
await add(undefined, undefined, { fail }) | ||
expect(fail).toHaveBeenCalledOnce() | ||
expect(fail).toHaveBeenCalledWith('No function source directory was specified') | ||
}) | ||
|
||
const normalizeFiles = function (fixtureDir, { name, mainFile, runtime, extension, srcDir, srcFile, schedule }) { | ||
interface FileData { | ||
name: string | ||
mainFile: string | ||
runtime: string | ||
extension: string | ||
srcDir?: string | ||
srcFile?: string | ||
schedule?: string | ||
} | ||
|
||
const normalizeFiles = function ( | ||
fixtureDir: string, | ||
{ name, mainFile, runtime, extension, srcDir, srcFile, schedule }: FileData, | ||
) { | ||
const mainFileA = normalize(`${fixtureDir}/${mainFile}`) | ||
const srcFileA = srcFile === undefined ? {} : { srcFile: normalize(`${fixtureDir}/${srcFile}`) } | ||
const srcDirA = srcDir ? { srcDir: resolve(fixtureDir, srcDir) } : {} | ||
|
@@ -117,7 +139,8 @@ const normalizeFiles = function (fixtureDir, { name, mainFile, runtime, extensio | |
test('Can list function main files with list()', async () => { | ||
const fixtureDir = `${FIXTURES_DIR}/list` | ||
const functions = await list(fixtureDir) | ||
expect(sortOn(functions, ['mainFile', 'extension'])).toEqual( | ||
expect(functions).toBeDefined() | ||
expect(sortOn(functions!, ['mainFile', 'extension'])).toEqual( | ||
[ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using
(side note for me to look into - I'm not sure why this isn't raising an error in CI) Would you be able to share some context on this change? I'm thinking we should be able to stick with the original assertions There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's sort of weird, but I cannot reproduce. Ran Verified config via Even tried reinstalling the editor and still zero success. Output tab in VS Code with eslint.debug enabled in .vscode/settings.json also shows nothing except ESLint working without errors. ![]() And this is the npm run lint run from root ![]() I'll try to reproduce in neovim. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was able to get the errors in Github Codespaces. This still has some "quirks": In Codespaces, running I know about --cache and stuff, but even without --cache eslint shows zero errors after build. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hope this is helpful and can help us find the cause! I don't think I can dig any further. Perhaps this is caused by project references in Typescript? https://www.typescriptlang.org/docs/handbook/project-references.html There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When you have some time, could you please remove your There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope, can only reproduce the same inconsistent ESLint behavior: Locally I've migrated to I'll open a separate PR with this proposal over the weekend. Also this should be solved by that PR:
UPD: I'll convert this to draft until this behavior is resolved |
||
{ name: 'four', mainFile: 'four.js/four.js.js', runtime: 'js', extension: '.js', srcDir: 'four.js' }, | ||
{ | ||
|
@@ -138,7 +161,8 @@ test('Can list function main files with list()', async () => { | |
test('Can list all function files with listAll()', async () => { | ||
const fixtureDir = `${FIXTURES_DIR}/list` | ||
const functions = await listAll(fixtureDir) | ||
expect(sortOn(functions, ['mainFile', 'extension'])).toEqual( | ||
expect(functions).toBeDefined() | ||
expect(sortOn(functions!, ['mainFile', 'extension'])).toEqual( | ||
[ | ||
{ | ||
name: 'four', | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A lot of these appear to still be necessary to suppress issues that have not yet been resolved
Running
npm run lint
returnsβ 23 problems (23 errors, 0 warnings)
It does look as though this line specifically (i.e.
'@typescript-eslint/restrict-template-expressions': 'off',
) can be removed.