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

Add prepare script, making it easy to install Prism from outside of NPM. #3699

Open
wants to merge 1 commit into
base: v2
Choose a base branch
from

Conversation

trusktr
Copy link

@trusktr trusktr commented Jun 30, 2023

The prepare script is the NPM-standard way in which outside-of-NPM packages can be build, for example with installed from a git location.

After merging this into the main branch (currently master), people will be able to do this:

npm install prismjs@github:PrismJS/prism

If they want to try it right now before v2 is merged (if this is merged into v2), they can do this:

npm install prismjs@github:PrismJS/prism#v2

Without this, such installations are not possible.

What NPM does during the install process is

  • it clones the specified repo,
  • checks out the specified git ref (f.e. the v2 in #v2),
  • installs dependencies including dev dependencies,
  • runs the prepare script if any (the prepare script will always have dev dependencies available to it),
  • and finally packages the result in the same way as npm pack such that build outputs are included in the final package that gets installed into the user's node_modules

This would be a way for people to easily test v2 right now and provide feedback.

The `prepare` script is the NPM-standard way in which outside-of-NPM packages can be build, for example with installed from a git location.

After merging this into the main branch (currently `master`), people will be able to do this:

```sh
npm install prismjs@github:PrismJS/prism
```

If they want to try it right now before v2 is merged (if this is merged into v2), they can do this:

```sh
npm install prismjs@github:PrismJS/prism#v2
```

Without this, such installations are not possible.

What NPM does during the `install` process is

- it clones the specified repo,
- checks out the specified git ref (f.e. `v2`),
- installs dependencies including dev dependencies,
- runs the `prepare` script if any (the `prepare` script will *always* have dev dependencies available to it),
- and finally packages the result in the same way as `npm pack` such that build outputs are included in the final package that gets installed into the user's node_modules

This would be a way for people to easily test v2 right now and provide feedback.
@trusktr trusktr marked this pull request as draft June 30, 2023 01:33
@github-actions
Copy link

No JS Changes

Generated by 🚫 dangerJS against f78f1e8

@trusktr
Copy link
Author

trusktr commented Jun 30, 2023

By the way, now that I've made this pull request, I can install and test this like so:

npm install prismjs@github:trusktr/prism#patch-1

I'll see if this currently works, and will update if not.

Copy link
Collaborator

@JaKXz JaKXz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @trusktr -- were you able to confirm this works for you? I'm happy to ✅

@trusktr
Copy link
Author

trusktr commented Jul 2, 2023

Will take it for a spin soon. I'm ironing out a few PRs in Docsify first, namely one PR to convert to type:module in package.json and all code to ESM, then we're due for a Prism update (Prism v1 uses require() which currently requires us to keep rollup-plugin-commonjs, so updating Prism will allow us to remove the final traces of CommonJS)

@trusktr
Copy link
Author

trusktr commented Jul 5, 2023

@JaKXz Here's an example that installs Prism from git, and then imports and initializes a new Prism() and calls .highlightAll():

https://github.com/trusktr/prism-v2-test

There's no syntax highlighting, and the docs aren't updated to describe how to use v2 yet, so I'm not yet sure how to get syntax coloring to be applied.

The build output also doesn't have type declaration outputs yet, so there wasn't yet intellisense or type checking in VS Code when I imported Prism. It guesses from the plain JS output:

Screenshot 2023-07-05 at 12 52 49 PM

Happy to help iron these details out.

I also think at this point in time we don't need to ship legacy CommonJS. To avoid maintenance, I'd say let other people build to CommonJS if they need to, f.e. they can use Rollup for that, and we can otherwise support the ES Module reality that all JS engines and build tools support nowadays.


But TLDR: the git install works! We can merge this if you'd like, and then work out the other details separately.

@trusktr trusktr mentioned this pull request Jul 5, 2023
2 tasks
@trusktr
Copy link
Author

trusktr commented Jul 6, 2023

This PR's commit is now included in

@trusktr trusktr marked this pull request as ready for review July 6, 2023 00:50
@trusktr trusktr changed the title A prepare script, making it easy to install Prism from outside of NPM. Add prepare script, making it easy to install Prism from outside of NPM. Jul 6, 2023
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.

2 participants