PrismJS / PrismJS/prism

[Brain storming] New language dependency system

Open
#2,880 40 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

core help wanted language-definitions
Dominant language
JavaScript
Stars
13k
Forks
1.4k
Avg merge
15h 36m
Merged PRs (30d)
3

Description

Motivation

Our current language dependency system has a few problems:

  • It is incompatible with ESM.

    The current system relies on load order to manage both require dependencies and optional dependencies. Optional dependencies simply cannot be expressed using ESM's static import syntax.

  • It has to be enforced by the user.

    Nothing stops our users from loading languages in the wrong order. We regularly get issues where people have this problem.

  • It does not support third-party language definitions.

    Right now, all dependencies have to be declared in components.json. This makes it very hard for authors of third-party languages to integrate their languages. They are essentially forced to write languages with zero dependencies.

The first problem is huge because ESM is a goal for v2.0.

Goals

Primary goals:

  • ESM-compatible.

    We have to be able to either write or create ESM source files. Source files have to be able to import each other to fulfill their require dependencies. (E.g. the JS language has to be able to import C-like.)

  • Optional dependencies.

    The dependency system has to support optional dependencies. They are the reason this issue exists and they are necessary for Prism.

Secondary goals:

  • Third-party authors should be able to "hook" into our dependency system.
  • Making the Node hack unnecessary.

Non-goals

  • Backwards-compatibility.

  • Modify dependencies.

    Modify dependencies are not strictly necessary. Right now, Prism has 13 modify dependencies. 12 of those can be easily converted into optional dependencies. Only 1 modify dependency will be difficult to convert into an optional dependency but I'm sure that we can find a solution for that.


@LeaVerou @Golmote @mAAdhaTTah

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the current language dependency system in the extending documentation, the dependency declarations in components.json, and the Node hack in components/prism-core.js. Compare the stated ESM, optional-dependency, and third-party-author goals with the current design. Done would require an agreed dependency-system design rather than a localized implementation.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.