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

Plugin system #152

Merged
merged 54 commits into from
Aug 16, 2021
Merged

Plugin system #152

merged 54 commits into from
Aug 16, 2021

Conversation

6utt3rfly
Copy link
Collaborator

Staging area before releasing all plugins to main

6utt3rfly and others added 29 commits June 5, 2021 17:05
…to source)

- Tests now restore original operation after running to avoid polluting other tests (since they modify static values versus instance values)
- filterProps test util now handles bool and null properly
…ependency injection

- Added plugin registration to JSEP. Plugins have a `name` and an `init` function that is called on registration with JSEP.
- Updated Object + Ternary plugins. Ternary plugin is registered by default
- Updated rollup to build each plugin as a separate output (all formats). Also delete dist folder before building.
- don't pollute the JSEP namespace from plugins. Use local constants instead.
Co-authored-by: Lea Verou <lea@verou.me>
(single object arg, single array of objects arg, multiple objects arg)
…to readme

- gobbleExpression and gobbleToken need to stop running hooks once a node is found, similar to how jsep checks when calling each successive gobble method now. This saves each hook from having to check for `env.node` (and potentially leading to future errors with 2 hooks parsing 2 sequential expressions as just the last node). Added unit tests.
- works in objects { ...a }, arrays [...a], function args fn(...a)
- NOTE: does not prevent `a ? ...b : ...c` or `...123`
() => x
x => x
(a, b) => x

Treats '=>' as a binary operator, but replaces the binary expression with the correct node type afterward
- supports // and /* */ style
- throws an error on missing closing */
a = 2
a *= 2

Treats each assignment operator as a binary operator, but replaces the binary expression with the 'AssignmentExpression' node type afterward
Update plugin system to use registration
@6utt3rfly
Copy link
Collaborator Author

@LeaVerou - I merged the approved PRs into this branch because I was thinking it would be better to ensure everything is working together and that we're happy with the API, documentation, etc. before merging all of it into master and releasing a new version. Buf if you would prefer to merge straight into main that's fine with me too 🤷🏻‍♀️

@LeaVerou
Copy link
Collaborator

LeaVerou commented Aug 2, 2021

I'm not used to the workflow of releasing a new version every time a PR is merged, but I'm not opposed to it either. 🤷🏼‍♀️
Ok, let's get consensus on the existing plugin PRs before merging. What's left to review?

@6utt3rfly
Copy link
Collaborator Author

not used to the workflow of releasing a new version every time a PR is merged

I typically don't either ... but I thought for a significant change like this it might make more sense. Especially if we're updating the readme docs but haven't yet published to npm 🤷🏻‍♀️

At any rate, I think it's nearly ready. I just updated the .npmignore file after I noticed what was included (npm pack builds a tar file to test).

One issue I noticed, when trying to use the build in a typescript project, is that the plugins themselves don't have a type definition:

import * as jsep from 'jsep';
import * as jsepArrow from 'jsep/dist/cjs/jsepArrow.cjs.js';

TS7016: Could not find a declaration file for module
'jsep/dist/cjs/jsepArrow.cjs.js'. 'node_modules/jsep/dist/cjs/jsepArrow.cjs.js' implicitly has an 'any' type.   Try `npm i --save-dev @types/jsep` if it exists or add a new declaration (.d.ts) file containing `declare module 'jsep/dist/cjs/jsepArrow.cjs.js';`

I could fix it by adding types to the tsd.ts file:

declare module 'jsep/dist/jsepArrow' {
  import * as jsep from 'jsep';
  const name: string;
  const init: (this: typeof jsep) => void;
}

declare module 'jsep/dist/cjs/jsepArrow.cjs.js' {
  import * as jsep from 'jsep';
  const name: string;
  const init: (this: typeof jsep) => void;
}

declare module 'jsep/dist/jsepArrow' {
  import * as jsep from 'jsep';
  const name: string;
  const init: (this: typeof jsep) => void;
}

declare module 'jsep/dist/iife/jsepArrow.iife.js' {
  import * as jsep from 'jsep';
  const name: string;
  const init: (this: typeof jsep) => void;
}

Or do you have a better suggestion? (I'd hate to do nothing and force 'allow implicit any', or have to manually declare the module)

@LeaVerou
Copy link
Collaborator

LeaVerou commented Aug 2, 2021

Can we have separate typings per module, included in its own directory? I'd like them to be as self-contained as possible.

@6utt3rfly
Copy link
Collaborator Author

6utt3rfly commented Aug 2, 2021

Maybe we should make the plugins more like a mono repo then? So that each plugin is individually published to npm (i.e. @jsep/arrow-plugin)? Might be nicer for versioning in the future if each has their own version? See #158

…n folder with its own package.json, rollup, etc. This keeps them more independent of jsep and allows for separate versioning
- remove .gitignore (root file works)
- remove rollup.config.js (and use a single file at the root)

Add plugin-specific types

Fix New plugin adding 'new' to a MemberExpression instead of the CallExpression
@6utt3rfly 6utt3rfly marked this pull request as ready for review August 15, 2021 19:10
@6utt3rfly
Copy link
Collaborator Author

@LeaVerou and @EricSmekens - I think this should have all of the PRs and changes that were already individually reviewed and approved. Do you want one more review of the branch before merging all to main? With the separate packages per plugin, should the github actions be updated?

@EricSmekens
Copy link
Owner

Approval on my side on merging this all to main.

Thank you for all your time and work on this! I think the actions should be updated, but I'm fine with that in a seperate pr.
(It currently uses npm publish, I guess for the multiple packages we need something different).

@6utt3rfly
Copy link
Collaborator Author

6utt3rfly commented Aug 15, 2021

I guess for the multiple packages we need something different).

I think each plugin package could be manually published (cd packages/arrow && npm publish) in the meantime? :-)

@LeaVerou
Copy link
Collaborator

Approval on my side too. We can always iterate with other PRs.

@6utt3rfly
Copy link
Collaborator Author

FYI - I started working on updating expression-eval to support the new node types and have been confirming that it can evaluate the nodes and use the updated jsep and packages. Merging! :-)

@6utt3rfly 6utt3rfly merged commit 8fec1fe into master Aug 16, 2021
@6utt3rfly 6utt3rfly deleted the plugin-system branch August 16, 2021 18:12
@dereklieu
Copy link

This is exciting, I'm looking forward to using the object plugin. Do you have plans to include this work in an upcoming release?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants