Full Code of codemirror/dev for AI

main 2cfd8b0a893c cached
15 files
28.9 KB
8.5k tokens
31 symbols
1 requests
Download .txt
Repository: codemirror/dev
Branch: main
Commit: 2cfd8b0a893c
Files: 15
Total size: 28.9 KB

Directory structure:
gitextract_c93w_9dg/

├── .github/
│   ├── FUNDING.yml
│   ├── ISSUE_TEMPLATE/
│   │   └── issue.yaml
│   └── workflows/
│       └── ci.yml
├── .gitignore
├── .npmignore
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── bin/
│   ├── build-readme.js
│   ├── cm.js
│   └── packages.js
├── demo/
│   ├── demo.ts
│   └── index.html
├── package.json
└── tsconfig.json

================================================
FILE CONTENTS
================================================

================================================
FILE: .github/FUNDING.yml
================================================
patreon: marijn
custom: ['https://www.paypal.com/paypalme/marijnhaverbeke', 'https://marijnhaverbeke.nl/fund/']
github: marijnh

================================================
FILE: .github/ISSUE_TEMPLATE/issue.yaml
================================================
name: Issue Report
description: Report a problem
body:
  - type: markdown
    attributes:
      value: Thanks for reporting an issue. If you have a question or request for support, use the [forum](https://discuss.codemirror.net/), **not** the bug tracker.
  - type: textarea
    id: descriptin
    attributes:
      label: Describe the issue
    validations:
      required: true
  - type: input
    id: browser
    attributes:
      label: Browser and platform
      description: If there is any chance at all that this is browser or platform related, please let us know which ones you tested. If IME or a virtual keyboard was involved, please mention which.
    validations:
      required: false
  - type: input
    id: try
    attributes:
      label: Reproduction link
      description: When practical, it helps a lot if you provide a script that reproduces the issue in [the CodeMirror sandbox](https://codemirror.net/try/) or another online code environment.
    validations:
      required: false


================================================
FILE: .github/workflows/ci.yml
================================================
name: main
on: [push, repository_dispatch]
jobs:
  build-and-test:
    runs-on: ubuntu-latest
    name: Build and test
    steps:
      - uses: styfle/cancel-workflow-action@0.9.1
        with:
          access_token: ${{ github.token }}

      - uses: actions/checkout@v1

      - uses: actions/setup-node@v2
        with:
          node-version: '22.11.0'

      - run: node bin/cm.js install

      - run: npm test


================================================
FILE: .gitignore
================================================
/node_modules
package-lock.json
/demo/demo.js*
/demo/demo.d.ts*
/demo/test/test.js*
/website
/buildhelper
/state
/view
/commands
/collab
/language
/language-data
/search
/lint
/autocomplete
/codemirror
/merge
/lsp-client
/lang-javascript
/lang-java
/lang-json
/lang-cpp
/lang-python
/lang-go
/lang-css
/lang-html
/lang-php
/lang-sql
/lang-rust
/lang-xml
/lang-markdown
/lang-lezer
/lang-wast
/lang-angular
/lang-vue
/lang-liquid
/lang-sass
/lang-jinja
/lang-less
/lang-yaml
/legacy-modes
/theme-one-dark
.tern-*


================================================
FILE: .npmignore
================================================
/*/src/*.js
/*/src/*.ts
!/*/src/*.d.ts
/*/src/*.map
/*/src/README.md
/*/test
/node_modules
/demo
/.travis.yml
.tern-*
/bin
/website


================================================
FILE: CONTRIBUTING.md
================================================
# How to contribute

- [Getting help](#getting-help)
- [Submitting bug reports](#submitting-bug-reports)
- [Contributing code](#contributing-code)

## Getting help

Community discussion, questions, and informal bug reporting is done on
the [discuss.CodeMirror forum](http://discuss.codemirror.net).

## Submitting bug reports

Report bugs on the
[GitHub issue tracker](http://github.com/codemirror/dev/issues).
Before reporting a bug, please read these pointers.

- The issue tracker is for *bugs*, not requests for help. Questions
  should be asked on the [forum](http://discuss.codemirror.net).

- Include information about the version of the code that exhibits the
  problem. For browser-related issues, include the browser, browser
  version, and operating system on which the problem occurred.

- Mention very precisely what went wrong. "X is broken" is not a good
  bug report. What did you expect to happen? What happened instead?
  Describe the exact steps a maintainer has to take to make the
  problem occur. A screencast can be useful, but is no substitute for
  a textual description.

- A great way to make it easy to reproduce your problem, if it can not
  be trivially reproduced on the website demos, is to submit a script
  that triggers the issue. The easiest way do do that is our
  [sandbox](https://codemirror.net/try/).

## Contributing code

Code written by "AI" language models (either partially or fully) is
**not welcome**. Both because you cannot guarantee it's not parroting
copyrighted content, and because it tends to be of low quality and a
waste of time to review.

- Make sure you have a [GitHub Account](https://github.com/signup/free)

- Fork the relevant repository
  ([how to fork a repo](https://help.github.com/articles/fork-a-repo))

- Create a local checkout of the code. You can use the
  [dev repository](https://github.com/codemirror/dev) to
  easily check out all core modules.

- Make your changes, and commit them

- Follow the code style of the rest of the project (see below).

- If your changes are easy to test or likely to regress, add tests in
  the relevant `test/` directory. Either put them in an existing
  `test-*.js` file, if they fit there, or add a new file.

- Make sure all tests pass. Run `npm run test` to verify tests pass.

- Submit a pull request ([how to create a pull request](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork)).
  Don't put more than one feature/fix in a single pull request.

By contributing code to CodeMirror you

 - Agree to license the contributed code under the project's [MIT
   license](https://github.com/CodeMirror/dev/blob/main/LICENSE).

 - Confirm that you have the right to contribute and license the code
   in question. (Either you hold all rights on the code, or the rights
   holder has explicitly granted the right to use it like this,
   through a compatible open source license or through a direct
   agreement with you.)

### Coding standards

- TypeScript, targeting an ES2018 runtime (i.e. don't use library
  elements added after ES2018).

- 2 spaces per indentation level, no tabs.

- No semicolons except when necessary.

- Follow the surrounding code when it comes to spacing, brace
  placement, etc.

- Brace-less single-statement bodies are encouraged (whenever they
  don't impact readability).

- [getdocs](https://github.com/marijnh/getdocs-ts)-style doc comments
  above items that are part of the public API.

- CodeMirror does *not* follow JSHint or JSLint prescribed style.
  Patches that try to 'fix' code to pass one of these linters will not
  be accepted.


================================================
FILE: LICENSE
================================================
MIT License

Copyright (C) 2018 by Marijn Haverbeke <marijn@haverbeke.berlin>, Adrian
Heine <mail@adrianheine.de>, and others

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.


================================================
FILE: README.md
================================================
# CodeMirror

[![Build Status](https://github.com/codemirror/dev/workflows/main/badge.svg)](https://github.com/codemirror/codemirror.next/actions)

This is the central repository for [CodeMirror](https://codemirror.net/). It holds the bug tracker and development scripts.

If you want to **use** CodeMirror, install the separate packages from npm, and ignore the contents of this repository. If you want to **develop on** CodeMirror, this repository provides scripts to install and work with the various packages.

To get started, make sure you are running [node.js](https://nodejs.org/) version 16. After cloning the repository, run

    node bin/cm.js install

to clone the packages that make up the system, install dependencies, and build the packages. At any time you can rebuild packages, either by running `npm run prepare` in their subdirectory, or all at once with

    node bin/cm.js build

Developing is best done by setting up

    npm run dev

which starts a server that automatically rebuilds the packages when their code changes and exposes a dev server on port 8090 running the [demo](http://localhost:8090) and [browser tests](http://localhost:8090/test/).

Please see [the website](https://codemirror.net/) for more information and [docs](https://codemirror.net/docs/ref).


================================================
FILE: bin/build-readme.js
================================================
// Function to build github-proof readmes that contain the package's API
// docs as HTML.

const {core} = require("./packages")
const {gather, gatherMany} = require("getdocs-ts")
const {build, browserImports} = require("builddocs")
const {join} = require("path"), fs = require("fs")

exports.buildReadme = function(pkg) {
  let imports = [type => {
    let sibling = type.typeSource && core.find(name => type.typeSource.startsWith("../" + name + "/"))
    if (sibling) return "https://codemirror.net/docs/ref#" + sibling + "." + type.type
  }, type => {
    if (/\blezer\/tree\b/.test(type.typeSource)) return `https://lezer.codemirror.net/docs/ref/#tree.${type.type}`
    if (/\blezer\/common\b/.test(type.typeSource)) return `https://lezer.codemirror.net/docs/ref/#common.${type.type}`
    if (/\blezer\/lr\b/.test(type.typeSource)) return `https://lezer.codemirror.net/docs/ref/#lr.${type.type}`
    if (/\blezer\/markdown\b/.test(type.typeSource)) return `https://github.com/lezer-parser/markdown#user-content-${type.type.toLowerCase()}`
    if (/\bstyle-mod\b/.test(type.typeSource)) return "https://github.com/marijnh/style-mod#documentation"
    if (/\bvscode-languageserver-/.test(type.typeSource))
      return `https://microsoft.github.io/language-server-protocol/specifications/specification-current#` +
        type.type[0].toLowerCase() + type.type.slice(1)
    if (type.type == "TextEdit") console.log(type.typeSource, type.type)
  }, browserImports]

  let template = fs.readFileSync(join(pkg.dir, pkg.name == "legacy-modes" ? "mode" : "src", "README.md"), "utf8")
  let html = ""

  if (pkg.name == "legacy-modes") {
    let mods = fs.readdirSync(join(pkg.dir, "mode")).filter(f => /\.d.ts$/.test(f)).map(file => {
      let name = /^(.*)\.d\.ts$/.exec(file)[1]
      return {name, filename: join(pkg.dir, "mode", file), basedir: pkg.dir}
    }), items = gatherMany(mods)
    for (let i = 0; i < mods.length; i++) {
      let {name} = mods[i]
      html += `\n<h3 id="${name}">mode/<a href="#${name}">${name}</a></h3>\n` + build({
        name: pkg.name,
        anchorPrefix: name + ".",
        allowUnresolvedTypes: false,
        imports
      }, items[i])
    }
    template += "\n$$$"
  } else {
    let placeholders = /(^|\n)@[^]*@\w+|\n@\w+/.exec(template)
    html = build({
      mainText: placeholders[0],
      name: pkg.name,
      anchorPrefix: "",
      allowUnresolvedTypes: false,
      imports
    }, gather({filename: pkg.main, basedir: pkg.dir}))
    template = template.slice(0, placeholders.index) + "\n$$$" + template.slice(placeholders.index + placeholders[0].length)
  }

  html = html.replace(/<\/?span.*?>/g, "")
    .replace(/id="(.*?)"/g, (_, id) => `id="user-content-${id.toLowerCase()}"`)
    .replace(/href="#(.*?)"/g, (_, id) => {
      let first = /^[^^.]*/.exec(id)[0]
      if (core.includes(first)) return `href="https://codemirror.net/docs/ref/#${id}"`
      if (first == pkg.name && id.length > first.length) id = id.slice(first.length + 1)
      return `href="#user-content-${id.toLowerCase()}"`
    })

  return template.replace("$$$", html)
}


================================================
FILE: bin/cm.js
================================================
#!/usr/bin/env node

// NOTE: Don't require anything from node_modules here, since the
// install script has to be able to run _before_ that exists.
const child = require("child_process"), fs = require("fs"), path = require("path"), {join} = path

let root = join(__dirname, "..")

const {loadPackages, nonCore} = require("./packages")

let {packages, packageNames, buildPackages} = loadPackages()

function start() {
  let command = process.argv[2]
  if (command && !["install", "--help"].includes(command)) assertInstalled()
  let args = process.argv.slice(3)
  let cmdFn = {
    packages: listPackages,
    status,
    build,
    devserver,
    release,
    unreleased,
    install,
    clean,
    commit,
    push,
    grep,
    "build-readme": buildReadme,
    test,
    run: runCmd,
    "--help": () => help(0)
  }[command]
  if (!cmdFn || cmdFn.length > args.length) help(1)
  new Promise(r => r(cmdFn.apply(null, args))).catch(e => error(e))
}

function help(status) {
  console.log(`Usage:
  cm install [--ssh]      Clone and symlink the packages, install deps, build
  cm packages             Emit a list of all pkg names
  cm status               Output git status, when interesting, for packages
  cm build                Build the bundle files
  cm clean                Delete files created by the build
  cm devserver [--source-map]
                          Start a dev server on port 8090
  cm release <package> [--edit] [--version <version>]
                          Create commits to tag a release
  cm build-readme <pkg>   Regenerate the readme file for a non-core package
  cm commit <args>        Run git commit in all packages that have changes
  cm push                 Run git push in packages that have new commits
  cm run <command>        Run the given command in each of the package dirs
  cm test [--no-browser]  Run the test suite of all the packages
  cm grep <pattern>       Grep through the source code for all packages
  cm --help`)
  process.exit(status)
}

function error(err) {
  console.error(err)
  process.exit(1)
}

function run(cmd, args, wd = root, { shell = false } = {}) {
  return child.execFileSync(cmd, args, {shell, cwd: wd, encoding: "utf8", stdio: ["ignore", "pipe", process.stderr]})
}

function replace(file, f) {
  fs.writeFileSync(file, f(fs.readFileSync(file, "utf8")))
}

function assertInstalled() {
  for (let p of packages) {
    if (!fs.existsSync(p.dir)) {
      console.error(`module ${p.name} is missing. Did you forget to run 'cm install'?`)
      process.exit(1)
    }
  }
}

function install(arg = null) {
  let base = arg == "--ssh" ? "git@github.com:codemirror/" : "https://github.com/codemirror/"
  if (arg && arg != "--ssh") help(1)

  for (let pkg of packages) {
    if (fs.existsSync(pkg.dir)) {
      console.warn(`Skipping cloning of ${pkg.name} (directory exists)`)
    } else {
      let origin = base + (pkg.name == "codemirror" ? "basic-setup" : pkg.name) + ".git"
      run("git", ["clone", origin, pkg.dir])
    }
  }

  console.log("Running npm install")
  run("npm", ["install"], root, {shell: process.platform == "win32"})
  console.log("Building modules")
  ;({packages, packageNames, buildPackages} = loadPackages())
  build()
}


function listPackages() {
  console.log(packages.map(p => p.name).join("\n"))
}

function status() {
  for (let pkg of packages) {
    let output = run("git", ["status", "-sb"], pkg.dir)
    if (output != "## main...origin/main\n")
      console.log(`${pkg.name}:\n${output}`)
  }
}

async function build() {
  console.info("Building...")
  let t0 = Date.now()
  await require("@marijn/buildtool").build(buildPackages.map(p => p.main), require("@codemirror/buildhelper/src/options").options)
  console.info(`Done in ${((Date.now() - t0) / 1000).toFixed(2)}s`)
}

function startServer() {
  let serve = join(root, "demo")
  let moduleserver = new (require("esmoduleserve/moduleserver"))({root: serve, maxDepth: 2})
  let serveStatic = require("serve-static")(serve, {
    setHeaders(res, path) {
      if (/try\/mods\//.test(path)) res.setHeader("Access-Control-Allow-Origin", "*")
    }
  })
  require("http").createServer((req, resp) => {
    if (/^\/test\/?($|\?)/.test(req.url)) {
      let runTests = require("@marijn/testtool")
      let {browserTests} = runTests.gatherTests(buildPackages.map(p => p.dir))
      resp.writeHead(200, {"content-type": "text/html"})
      resp.end(runTests.testHTML(browserTests.map(f => path.relative(serve, f)), {
        html: `<title>CM6 view tests</title>
<h1>CM6 view tests</h1>
<div id="workspace" style="opacity: 0; position: fixed; top: 0; left: 0; width: 20em;"></div>`
      }))
    } else {
      moduleserver.handleRequest(req, resp) || serveStatic(req, resp, _err => {
        resp.statusCode = 404
        resp.end('Not found')
      })
    }
  }).listen(8090, process.env.OPEN ? undefined : "127.0.0.1")
  console.log("Dev server listening on 8090")
}

function devserver(...args) {
  let options = {
    sourceMap : args.includes('--source-map'),
    ...require("@codemirror/buildhelper/src/options").options
  }
  require("@marijn/buildtool").watch(buildPackages.map(p => p.main).filter(f => f), [join(root, "demo/demo.ts")], options)
  startServer()
}

function changelog(pkg, since) {
  let commits = run("git", ["log", "--format=%B%n", "--reverse", since + "..main"], pkg.dir)
  let result = {fix: [], feature: [], breaking: []}
  let re = /\n\r?\n(BREAKING|FIX|FEATURE):\s*([^]*?)(?=\r?\n\r?\n|\r?\n?$)/g, match
  while (match = re.exec(commits)) result[match[1].toLowerCase()].push(match[2].replace(/\r?\n/g, " "))
  return result
}

function bumpVersion(version, changes) {
  let [major, minor, patch] = version.split(".")
  if (major == "0") return changes.breaking.length ? `0.${Number(minor) + 1}.0` : `0.${minor}.${Number(patch) + 1}`
  if (changes.breaking.length) return `${Number(major) + 1}.0.0`
  if (changes.feature.length) return `${major}.${Number(minor) + 1}.0`
  if (changes.fix.length) return `${major}.${minor}.${Number(patch) + 1}`
  throw new Error("No new release notes!")
}

function releaseNotes(changes, version) {
  let pad = n => n < 10 ? "0" + n : n
  let d = new Date, date = d.getFullYear() + "-" + pad(d.getMonth() + 1) + "-" + pad(d.getDate())

  let types = {breaking: "Breaking changes", fix: "Bug fixes", feature: "New features"}

  let refTarget = "https://codemirror.net/docs/ref/"
  let head = `## ${version} (${date})\n\n`, body = ""
  for (let type in types) {
    let messages = changes[type]
    if (messages.length) body += `### ${types[type]}\n\n`
    messages.forEach(message => body += message.replace(/\]\(##/g, "](" + refTarget + "#") + "\n\n")
  }
  return {head, body}
}

function setModuleVersion(pkg, version) {
  let file = join(pkg.dir, "package.json")
  fs.writeFileSync(file, fs.readFileSync(file, "utf8").replace(/"version":\s*".*?"/, `"version": "${version}"`))
}

function updateDependencyVersion(pkg, version) {
  let changed = []
  for (let other of packages) if (other != pkg) {
    let pkgFile = join(other.dir, "package.json"), text = fs.readFileSync(pkgFile, "utf8")
    let updated = text.replace(new RegExp(`("@codemirror/${pkg.name}": ")(.*?)"`, "g"), (_, m) => m + "^" + version + '"')
    if (updated != text) {
      changed.push(other)
      fs.writeFileSync(pkgFile, updated)
      run("git", ["add", "package.json"], other.dir)
      let lastMsg = run("git", ["log", "-1", "--pretty=%B"], other.dir)
      if (/^Bump dependency /.test(lastMsg))
        run("git", ["commit", "--amend", "-m", lastMsg.trimEnd() + ", @codemirror/" + pkg.name], other.dir)
      else
        run("git", ["commit", "-m", "Bump dependency for @codemirror/" + pkg.name], other.dir)
    }
  }
  return changed
}

function version(pkg) {
  return require(join(pkg.dir, "package.json")).version
}

const mainVersion = /^0.\d+|\d+/

function release(...args) {
  let setVersion, edit = false, pkgName, pkg
  for (let i = 0; i < args.length; i++) {
    let arg = args[i]
    if (arg == "--edit") edit = true
    else if (arg == "--version" && i < args.length) setVersion = args[++i]
    else if (!pkgName && arg[0] != "-") pkgName = arg
    else help(1)
  }
  if (!pkgName || !(pkg = packageNames[pkgName])) help(1)

  run("git", ["pull"], pkg.dir)

  let {changes, newVersion} = doRelease(pkg, setVersion, {edit})

  // Turned off for now, since this creates a huge mess on accidental
  // major version bumps. Maybe add a manual utility for it?
  if (false && mainVersion.exec(newVersion)[0] != mainVersion.exec(version(pkg))[0]) {
    let updated = updateDependencyVersion(pkg, newVersion)
    if (updated.length) console.log(`Updated dependencies in ${updated.map(p => p.name).join(", ")}`)
  }
}

function doRelease(pkg, newVersion, {edit = false, defaultChanges = null}) {
  let log = join(pkg.dir, "CHANGELOG.md")
  let newPackage = !fs.existsSync(log)

  let currentVersion = version(pkg)
  let changes = newPackage ? {fix: [], feature: [], breaking: ["First numbered release."]} : changelog(pkg, currentVersion)
  if (defaultChanges && !changes.fix.length && !changes.feature.length && !changes.breaking.length) changes = defaultChanges
  if (!newVersion) newVersion = newPackage ? currentVersion : bumpVersion(currentVersion, changes)
  console.log(`Creating @codemirror/${pkg.name} ${newVersion}`)

  let notes = releaseNotes(changes, newVersion)
  if (edit) notes = editReleaseNotes(notes)

  setModuleVersion(pkg, newVersion)
  fs.writeFileSync(log, notes.head + notes.body + (newPackage ? "" : fs.readFileSync(log, "utf8")))
  run("git", ["add", "package.json"], pkg.dir)
  run("git", ["add", "CHANGELOG.md"], pkg.dir)
  run("git", ["commit", "-m", `Mark version ${newVersion}`], pkg.dir)
  run("git", ["tag", newVersion, "-m", `Version ${newVersion}\n\n${notes.body}`, "--cleanup=verbatim"], pkg.dir)

  return {changes, newVersion}
}

function editReleaseNotes(notes) {
  let noteFile = join(root, "notes.txt")
  fs.writeFileSync(noteFile, notes.head + notes.body)
  run(process.env.EDITOR || "emacs", [noteFile])
  let edited = fs.readFileSync(noteFile)
  fs.unlinkSync(noteFile)
  if (!/\S/.test(edited)) process.exit(0)
  let split = /^(.*)\n+([^]*)/.exec(edited)
  return {head: split[1] + "\n\n", body: split[2]}
}

function unreleased() {
  for (let pkg of packages) {
    let ver = version(pkg), changes = changelog(pkg, ver)
    if (changes.fix.length || changes.feature.length || changes.breaking.length)
      console.log(pkg.name + ":\n\n" + releaseNotes(changes, ver).body)
  }
}

function clean() {
  for (let pkg of buildPackages)
    run("rm", ["-rf", "dist"], pkg.dir)
}

function commit(...args) {
  for (let pkg of packages) {
    if (run("git", ["diff"], pkg.dir) || run("git", ["diff", "--cached"], pkg.dir))
      console.log(pkg.name + ":\n" + run("git", ["commit"].concat(args), pkg.dir))
  }
}

function push(...args) {
  for (let pkg of packages) {
    if (/\bahead\b/.test(run("git", ["status", "-sb"], pkg.dir)))
      run("git", ["push", ...args], pkg.dir)
  }
}

function grep(pattern) {
  let files = [join(root, "demo", "demo.ts")]
  function add(dir, ext) {
    let list
    try { list = fs.readdirSync(dir) }
    catch (_) { return }
    for (let f of list) if (ext.includes(/^[^.]*(.*)/.exec(f)[1])) {
      files.push(path.relative(process.cwd(), join(dir, f)))
    }
  }
  for (let pkg of packages) {
    if (pkg.name == "legacy-modes") {
      add(join(pkg.dir, "mode"), [".js", ".d.ts"])
    } else {
      add(join(pkg.dir, "src"), [".ts"])
      add(join(pkg.dir, "test"), [".ts"])
    }
  }
  try {
    console.log(run("grep", ["--color", "-nH", "-e", pattern].concat(files), process.cwd()))
  } catch(e) {
    process.exit(1)
  }
}

function runCmd(cmd, ...args) {
  for (let pkg of packages) {
    console.log(pkg.name + ":")
    try {
      console.log(run(cmd, args, pkg.dir))
    } catch (e) {
      console.log(e.toString())
      process.exit(1)
    }
  }
}

function buildReadme(name) {
  if (!nonCore.includes(name)) help(1)
  let pkg = packageNames[name]
  fs.writeFileSync(join(pkg.dir, "README.md"), require("./build-readme").buildReadme(pkg))
}

function test(...args) {
  let runTests = require("@marijn/testtool")
  let {tests, browserTests} = runTests.gatherTests(buildPackages.map(p => p.dir))
  let browsers = [], grep, noBrowser = false
  for (let i = 0; i < args.length; i++) {
    if (args[i] == "--firefox") browsers.push("firefox")
    if (args[i] == "--chrome") browser.push("chrome")
    if (args[i] == "--no-browser") noBrowser = true
    if (args[i] == "--grep") grep = args[++i]
  }
  if (!browsers.length && !noBrowser) browsers.push("chrome")
  runTests.runTests({tests, browserTests, browsers, grep}).then(failed => process.exit(failed ? 1 : 0))
}

start()


================================================
FILE: bin/packages.js
================================================
const fs = require("fs"), {join} = require("path")

exports.core = [
  "state",
  "view",
  "language",
  "commands",
  "search",
  "autocomplete",
  "lint",
  "collab",
  "language-data",
  "merge",
  "lsp-client",
  "codemirror",
]
exports.nonCore = [
  "lang-javascript",
  "lang-java",
  "lang-json",
  "lang-cpp",
  "lang-php",
  "lang-python",
  "lang-go",
  "lang-css",
  "lang-sass",
  "lang-html",
  "lang-sql",
  "lang-rust",
  "lang-xml",
  "lang-markdown",
  "lang-lezer",
  "lang-wast",
  "lang-angular",
  "lang-vue",
  "lang-liquid",
  "lang-less",
  "lang-yaml",
  "lang-jinja",
  "legacy-modes",
  "theme-one-dark"
]

exports.all = exports.core.concat(exports.nonCore)

class Pkg {
  constructor(name) {
    this.name = name
    this.dir = join(__dirname, "..", name)
    this.main = null
    if (name != "legacy-modes" && fs.existsSync(this.dir)) {
      let files = fs.readdirSync(join(this.dir, "src")).filter(f => /^[^.]+\.ts$/.test(f))
      let main = files.length == 1 ? files[0] : files.includes("index.ts") ? "index.ts"
          : files.includes(name.replace(/^(theme-|lang-)/, "") + ".ts") ? name.replace(/^(theme-|lang-)/, "") + ".ts" : null
      if (!main) throw new Error("Couldn't find a main script for " + name)
      this.main = join(this.dir, "src", main)
    }
  }
}
exports.Pkg = Pkg

exports.loadPackages = function loadPackages() {
  let packages = exports.all.map(n => new Pkg(n))
  let packageNames = Object.create(null)
  for (let p of packages) packageNames[p.name] = p
  return {packages, packageNames, buildPackages: packages.filter(p => p.main)}
}


================================================
FILE: demo/demo.ts
================================================
import {EditorView, basicSetup} from "codemirror"
import {javascript} from "@codemirror/lang-javascript"

;(window as any).view = new EditorView({
  doc: 'console.log("Hello world")',
  extensions: [
    basicSetup,
    javascript(),
  ],
  parent: document.body
})


================================================
FILE: demo/index.html
================================================
<!doctype html>
<meta charset=utf8>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>CM6 demo</title>

<style>
.cm-editor { height: 300px; border: 1px solid #ddd}
.cm-scroller { overflow: auto; }
</style>

<h1>CM6</h1>

<script type=module src="_m/demo.js"></script>


================================================
FILE: package.json
================================================
{
  "description": "Development environment for the CodeMirror 6 packages",
  "scripts": {
    "test": "node bin/cm.js test",
    "test-node": "node bin/cm.js test --no-browser",
    "prepare": "node bin/cm.js build",
    "dev": "node bin/cm.js devserver"
  },
  "author": "Marijn Haverbeke <marijn@haverbeke.berlin>",
  "license": "MIT",
  "devDependencies": {
    "@codemirror/buildhelper": "^1.0.2",
    "esmoduleserve": "^0.2.0",
    "serve-static": "^1.14.1",
    "getdocs-ts": "^1.0.0",
    "builddocs": "^1.0.0"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/codemirror/dev.git"
  },
  "workspaces": [
    "*"
  ],
  "private": true
}


================================================
FILE: tsconfig.json
================================================
{
  "compilerOptions": {
    "lib": ["es2018", "dom", "scripthost"],
    "types": ["mocha"],
    "stripInternal": true,
    "typeRoots": ["./node_modules/@types"],
    "noUnusedLocals": true,
    "strict": true,
    "target": "es2018",
    "module": "es2020",
    "newLine": "lf",
    "moduleResolution": "node",
    "paths": {
      "@codemirror/state": ["./state/src/index.ts"],
      "@codemirror/view": ["./view/src/index.ts"],
      "@codemirror/commands": ["./commands/src/commands.ts"],
      "@codemirror/collab": ["./collab/src/collab.ts"],
      "@codemirror/language": ["./language/src/index.ts"],
      "@codemirror/language-data": ["./language-data/src/language-data.ts"],
      "@codemirror/search": ["./search/src/search.ts"],
      "@codemirror/lint": ["./lint/src/lint.ts"],
      "@codemirror/autocomplete": ["./autocomplete/src/index.ts"],
      "@codemirror/merge": ["./merge/src/index.ts"],
      "@codemirror/lsp-client": ["./lsp-client/src/index.ts"],
      "codemirror": ["./codemirror/src/codemirror.ts"],
      "@codemirror/lang-javascript": ["./lang-javascript/src/index.ts"],
      "@codemirror/lang-java": ["./lang-java/src/java.ts"],
      "@codemirror/lang-json": ["./lang-json/src/json.ts"],
      "@codemirror/lang-cpp": ["./lang-cpp/src/cpp.ts"],
      "@codemirror/lang-python": ["./lang-python/src/python.ts"],
      "@codemirror/lang-go": ["./lang-go/src/index.ts"],
      "@codemirror/lang-css": ["./lang-css/src/css.ts"],
      "@codemirror/lang-html": ["./lang-html/src/html.ts"],
      "@codemirror/lang-sql": ["./lang-sql/src/sql.ts"],
      "@codemirror/lang-rust": ["./lang-rust/src/rust.ts"],
      "@codemirror/lang-xml": ["./lang-xml/src/xml.ts"],
      "@codemirror/lang-markdown": ["./lang-markdown/src/index.ts"],
      "@codemirror/lang-lezer": ["./lang-lezer/src/index.ts"],
      "@codemirror/lang-php": ["./lang-php/src/php.ts"],
      "@codemirror/lang-wast": ["./lang-wast/src/wast.ts"],
      "@codemirror/lang-angular": ["./lang-angular/src/angular.ts"],
      "@codemirror/lang-vue": ["./lang-vue/src/vue.ts"],
      "@codemirror/lang-liquid": ["./lang-vue/src/liquid.ts"],
      "@codemirror/lang-sass": ["./lang-sass/src/sass.ts"],
      "@codemirror/lang-less": ["./lang-less/src/less.ts"],
      "@codemirror/lang-yaml": ["./lang-yaml/src/yaml.ts"],
      "@codemirror/lang-jinja": ["./lang-jinja/src/jinja.ts"],
      "@codemirror/theme-one-dark": ["./theme-one-dark/src/one-dark.ts"]
    }
  },
  "include": ["*/src/*.ts", "*/test/*.ts", "demo/demo.ts"],
}
Download .txt
gitextract_c93w_9dg/

├── .github/
│   ├── FUNDING.yml
│   ├── ISSUE_TEMPLATE/
│   │   └── issue.yaml
│   └── workflows/
│       └── ci.yml
├── .gitignore
├── .npmignore
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── bin/
│   ├── build-readme.js
│   ├── cm.js
│   └── packages.js
├── demo/
│   ├── demo.ts
│   └── index.html
├── package.json
└── tsconfig.json
Download .txt
SYMBOL INDEX (31 symbols across 2 files)

FILE: bin/cm.js
  function start (line 13) | function start() {
  function help (line 38) | function help(status) {
  function error (line 59) | function error(err) {
  function run (line 64) | function run(cmd, args, wd = root, { shell = false } = {}) {
  function replace (line 68) | function replace(file, f) {
  function assertInstalled (line 72) | function assertInstalled() {
  function install (line 81) | function install(arg = null) {
  function listPackages (line 102) | function listPackages() {
  function status (line 106) | function status() {
  function build (line 114) | async function build() {
  function startServer (line 121) | function startServer() {
  function devserver (line 149) | function devserver(...args) {
  function changelog (line 158) | function changelog(pkg, since) {
  function bumpVersion (line 166) | function bumpVersion(version, changes) {
  function releaseNotes (line 175) | function releaseNotes(changes, version) {
  function setModuleVersion (line 191) | function setModuleVersion(pkg, version) {
  function updateDependencyVersion (line 196) | function updateDependencyVersion(pkg, version) {
  function version (line 215) | function version(pkg) {
  function release (line 221) | function release(...args) {
  function doRelease (line 244) | function doRelease(pkg, newVersion, {edit = false, defaultChanges = null...
  function editReleaseNotes (line 267) | function editReleaseNotes(notes) {
  function unreleased (line 278) | function unreleased() {
  function clean (line 286) | function clean() {
  function commit (line 291) | function commit(...args) {
  function push (line 298) | function push(...args) {
  function grep (line 305) | function grep(pattern) {
  function runCmd (line 330) | function runCmd(cmd, ...args) {
  function buildReadme (line 342) | function buildReadme(name) {
  function test (line 348) | function test(...args) {

FILE: bin/packages.js
  class Pkg (line 46) | class Pkg {
    method constructor (line 47) | constructor(name) {
Condensed preview — 15 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (32K chars).
[
  {
    "path": ".github/FUNDING.yml",
    "chars": 127,
    "preview": "patreon: marijn\ncustom: ['https://www.paypal.com/paypalme/marijnhaverbeke', 'https://marijnhaverbeke.nl/fund/']\ngithub: "
  },
  {
    "path": ".github/ISSUE_TEMPLATE/issue.yaml",
    "chars": 1006,
    "preview": "name: Issue Report\ndescription: Report a problem\nbody:\n  - type: markdown\n    attributes:\n      value: Thanks for report"
  },
  {
    "path": ".github/workflows/ci.yml",
    "chars": 418,
    "preview": "name: main\non: [push, repository_dispatch]\njobs:\n  build-and-test:\n    runs-on: ubuntu-latest\n    name: Build and test\n "
  },
  {
    "path": ".gitignore",
    "chars": 512,
    "preview": "/node_modules\npackage-lock.json\n/demo/demo.js*\n/demo/demo.d.ts*\n/demo/test/test.js*\n/website\n/buildhelper\n/state\n/view\n/"
  },
  {
    "path": ".npmignore",
    "chars": 132,
    "preview": "/*/src/*.js\n/*/src/*.ts\n!/*/src/*.d.ts\n/*/src/*.map\n/*/src/README.md\n/*/test\n/node_modules\n/demo\n/.travis.yml\n.tern-*\n/b"
  },
  {
    "path": "CONTRIBUTING.md",
    "chars": 3695,
    "preview": "# How to contribute\n\n- [Getting help](#getting-help)\n- [Submitting bug reports](#submitting-bug-reports)\n- [Contributing"
  },
  {
    "path": "LICENSE",
    "chars": 1150,
    "preview": "MIT License\n\nCopyright (C) 2018 by Marijn Haverbeke <marijn@haverbeke.berlin>, Adrian\nHeine <mail@adrianheine.de>, and o"
  },
  {
    "path": "README.md",
    "chars": 1290,
    "preview": "# CodeMirror\n\n[![Build Status](https://github.com/codemirror/dev/workflows/main/badge.svg)](https://github.com/codemirro"
  },
  {
    "path": "bin/build-readme.js",
    "chars": 3101,
    "preview": "// Function to build github-proof readmes that contain the package's API\n// docs as HTML.\n\nconst {core} = require(\"./pac"
  },
  {
    "path": "bin/cm.js",
    "chars": 12766,
    "preview": "#!/usr/bin/env node\n\n// NOTE: Don't require anything from node_modules here, since the\n// install script has to be able "
  },
  {
    "path": "bin/packages.js",
    "chars": 1596,
    "preview": "const fs = require(\"fs\"), {join} = require(\"path\")\n\nexports.core = [\n  \"state\",\n  \"view\",\n  \"language\",\n  \"commands\",\n  "
  },
  {
    "path": "demo/demo.ts",
    "chars": 266,
    "preview": "import {EditorView, basicSetup} from \"codemirror\"\nimport {javascript} from \"@codemirror/lang-javascript\"\n\n;(window as an"
  },
  {
    "path": "demo/index.html",
    "chars": 294,
    "preview": "<!doctype html>\n<meta charset=utf8>\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n<title>CM6 demo"
  },
  {
    "path": "package.json",
    "chars": 668,
    "preview": "{\n  \"description\": \"Development environment for the CodeMirror 6 packages\",\n  \"scripts\": {\n    \"test\": \"node bin/cm.js t"
  },
  {
    "path": "tsconfig.json",
    "chars": 2522,
    "preview": "{\n  \"compilerOptions\": {\n    \"lib\": [\"es2018\", \"dom\", \"scripthost\"],\n    \"types\": [\"mocha\"],\n    \"stripInternal\": true,\n"
  }
]

About this extraction

This page contains the full source code of the codemirror/dev GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 15 files (28.9 KB), approximately 8.5k tokens, and a symbol index with 31 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!