-
Notifications
You must be signed in to change notification settings - Fork 1
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
chore: restructure monorepo #231
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,13 +33,5 @@ | |
"node": "22.11.0", | ||
"pnpm": "9.14.2" | ||
}, | ||
"pnpm": { | ||
"patchedDependencies": { | ||
"fixturify-project": "patches/fixturify-project.patch" | ||
}, | ||
"overrides": { | ||
"@sveltejs/vite-plugin-svelte": "^4.0.0" | ||
} | ||
}, | ||
"packageManager": "[email protected]+sha512.6e2baf77d06b9362294152c851c4f278ede37ab1eba3a55fda317a4a17b209f4dbb973fb250a77abc463a341fcb1f17f17cfa24091c4eb319cda0d9b84278387" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dist |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{ | ||
"name": "@sheepdog/core", | ||
"version": "0.0.1", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/mainmatter/sheepdog.git" | ||
}, | ||
"main": "./dist/index.js", | ||
"type": "module", | ||
"scripts": { | ||
"build": "tsc --outDir dist --declaration --sourceMap false && publint", | ||
"prepack": "pnpm build", | ||
"prepare": "pnpm build" | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"exports": { | ||
".": { | ||
"types": "./dist/index.d.ts", | ||
"svelte": "./dist/index.js", | ||
"import": "./dist/index.js" | ||
}, | ||
"./utils": { | ||
"types": "./dist/utils.d.ts", | ||
"svelte": "./dist/utils.js", | ||
"import": "./dist/utils.js" | ||
}, | ||
"./vite": { | ||
"types": "./dist/vite.d.ts", | ||
"svelte": "./dist/vite.js", | ||
"import": "./dist/vite.js" | ||
} | ||
}, | ||
"types": "./dist/index.d.ts", | ||
"svelte": "./dist/index.js", | ||
"dependencies": { | ||
"acorn": "^8.11.3", | ||
"esm-env": "^1.1.4", | ||
"esrap": "^1.2.2", | ||
"zimmerframe": "^1.1.2" | ||
}, | ||
"volta": { | ||
"extends": "../../package.json" | ||
}, | ||
"devDependencies": { | ||
"publint": "^0.2.7", | ||
"vite": "^5.2.11" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"composite": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { DEV } from 'esm-env'; | ||
import { CancelationError } from './index'; | ||
import type { TaskFunction } from './index'; | ||
|
||
/** | ||
* Utility method to know if a `perform` thrown because it was canceled | ||
*/ | ||
export const didCancel = (e: Error | CancelationError) => { | ||
return e instanceof CancelationError; | ||
}; | ||
|
||
/** | ||
* A Promise that will resolve after {ms} milliseconds | ||
*/ | ||
export async function timeout(ms: number) { | ||
return new Promise((resolve) => setTimeout(resolve, ms)); | ||
} | ||
|
||
/** | ||
* A function to mark your function to be transformable by the | ||
* async transform vite plugin. It will error out in dev mode | ||
* if you didn't add the plugin. | ||
*/ | ||
export function transform<TArgs, TReturn>( | ||
fn: TaskFunction<TArgs, TReturn>, | ||
): TaskFunction<TArgs, TReturn> { | ||
if (DEV) { | ||
throw new Error( | ||
'You are using the transform function without the vite plugin. Please add the `asyncTransform` plugin to your `vite.config.ts`', | ||
); | ||
} | ||
return fn; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
import type { | ||
ArrowFunctionExpression, | ||
AwaitExpression, | ||
BlockStatement, | ||
CallExpression, | ||
FunctionExpression, | ||
ImportDeclaration, | ||
} from 'acorn'; | ||
import type { Plugin } from 'vite'; | ||
|
||
type Nodes = | ||
| ImportDeclaration | ||
| FunctionExpression | ||
| ArrowFunctionExpression | ||
| CallExpression | ||
| BlockStatement | ||
| AwaitExpression; | ||
|
||
export async function asyncTransform() { | ||
const { parse } = await import('acorn'); | ||
const { print } = await import('esrap'); | ||
const { walk } = await import('zimmerframe'); | ||
|
||
return { | ||
name: 'sheepdog-async-transform', | ||
async transform(code, id) { | ||
try { | ||
const ast = parse(code, { | ||
ecmaVersion: 'latest', | ||
locations: true, | ||
sourceType: 'module', | ||
}); | ||
let task_fn_name: string; | ||
const transform_fn_names = new Set<string>(); | ||
// let's walk once to find the name (we were using a promise before but that's just messy) | ||
walk( | ||
ast as unknown as ImportDeclaration, | ||
{}, | ||
{ | ||
ImportDeclaration(node) { | ||
if ( | ||
node.source.value === '@sheepdog/svelte' || | ||
node.source.value === '@sheepdog/svelte/task' || | ||
node.source.value === '@sheepdog/svelte/utils' | ||
) { | ||
const task_fn = node.specifiers.find((specifier) => { | ||
return ( | ||
specifier.type === 'ImportSpecifier' && | ||
specifier.imported.type === 'Identifier' && | ||
specifier.imported.name === 'task' | ||
); | ||
}); | ||
const transform_fn = node.specifiers.find((specifier) => { | ||
return ( | ||
specifier.type === 'ImportSpecifier' && | ||
specifier.imported.type === 'Identifier' && | ||
specifier.imported.name === 'transform' | ||
); | ||
}); | ||
if (transform_fn && transform_fn.type === 'ImportSpecifier') { | ||
transform_fn_names.add(transform_fn.local.name); | ||
} | ||
if (task_fn && task_fn.type === 'ImportSpecifier') { | ||
task_fn_name = task_fn.local.name; | ||
} | ||
} | ||
}, | ||
}, | ||
); | ||
let changed = false; | ||
const returned = walk( | ||
ast as unknown as Nodes, | ||
{ | ||
transform: false, | ||
}, | ||
{ | ||
AwaitExpression(node, { next, state }) { | ||
if (state.transform) { | ||
next(); | ||
node.type = 'YieldExpression' as never; | ||
} | ||
}, | ||
CallExpression(node, { state, next }) { | ||
let local_changed = false; | ||
let task_arg: (typeof node)['arguments'][number] | undefined; | ||
if ( | ||
(node.callee.type === 'Identifier' && | ||
(node.callee.name === task_fn_name || | ||
transform_fn_names.has(node.callee.name))) || | ||
(node.callee.type === 'MemberExpression' && | ||
node.callee.object.type === 'Identifier' && | ||
node.callee.object.name === task_fn_name) | ||
) { | ||
task_arg = node.arguments[0]; | ||
if (task_arg && task_arg.type === 'ArrowFunctionExpression' && task_arg.async) { | ||
const to_change = task_arg as unknown as FunctionExpression; | ||
to_change.type = 'FunctionExpression'; | ||
to_change.generator = true; | ||
next({ ...state, transform: true }); | ||
changed = true; | ||
local_changed = true; | ||
} else if ( | ||
task_arg && | ||
task_arg.type === 'FunctionExpression' && | ||
!task_arg.generator && | ||
task_arg.async | ||
) { | ||
const to_change = task_arg as unknown as FunctionExpression; | ||
to_change.generator = true; | ||
next({ ...state, transform: true }); | ||
changed = true; | ||
local_changed = true; | ||
} | ||
} | ||
if (!local_changed) { | ||
next(); | ||
} | ||
if ( | ||
task_arg && | ||
node.callee.type === 'Identifier' && | ||
transform_fn_names.has(node.callee.name) | ||
) { | ||
return task_arg as never; | ||
} | ||
}, | ||
}, | ||
) as unknown as typeof ast; | ||
|
||
if (changed) { | ||
return { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
...print(returned as any, { | ||
sourceMapContent: code, | ||
sourceMapSource: id, | ||
}), | ||
}; | ||
} | ||
} catch (e) { | ||
console.error(e); | ||
/** in case parsing fails */ | ||
} | ||
}, | ||
} satisfies Plugin; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
engine-strict=true | ||
engine-strict=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,3 @@ | ||
import { DEV } from 'esm-env'; | ||
import { CancelationError } from './core'; | ||
import type { TaskFunction } from './core'; | ||
import { didCancel, timeout, transform } from '@sheepdog/core/utils'; | ||
|
||
/** | ||
* Utility method to know if a `perform` thrown because it was canceled | ||
*/ | ||
export const didCancel = (e: Error | CancelationError) => { | ||
return e instanceof CancelationError; | ||
}; | ||
|
||
/** | ||
* A Promise that will resolve after {ms} milliseconds | ||
*/ | ||
export async function timeout(ms: number) { | ||
return new Promise((resolve) => setTimeout(resolve, ms)); | ||
} | ||
|
||
/** | ||
* A function to mark your function to be transformable by the | ||
* async transform vite plugin. It will error out in dev mode | ||
* if you didn't add the plugin. | ||
*/ | ||
export function transform<TArgs, TReturn>( | ||
fn: TaskFunction<TArgs, TReturn>, | ||
): TaskFunction<TArgs, TReturn> { | ||
if (DEV) { | ||
throw new Error( | ||
'You are using the transform function without the vite plugin. Please add the `asyncTransform` plugin to your `vite.config.ts`', | ||
); | ||
} | ||
return fn; | ||
} | ||
export { didCancel, timeout, transform }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
so I don't understand why you needed to add this 🤔 the line above you're dealing with value possibly being null/undefined but here you're asserting that it's not? it seems like a real type change in a PR that is otherwise just moving things around
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.
I think the switcharoo that we did with the tsconfig caused the surface of this problem...but it's really a non problem because you can try to delete
null
orundefined
and it will just not delete anything.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.
yes but that should probably be reflected in the types no? what's the signature for delete?
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.
Nope, i think this is one of the rare instances when TS is more strict than it needs to be
we could make the
Set
beSet<AbortController | undefined | null>
but tbf i'm perfectly fine with just asserting the existance.