Add pure annotations option #6

Closed
timdown wants to merge 1 commit from add-pure-annotations-option into main
timdown commented 2022-07-12 00:36:01 +02:00 (Migrated from github.com)

Adds --source-map and --disable-pure-annotations command line options to cm-buildhelper.

We're using https://github.com/replit/codemirror-emacs and found it not working correctly in production mode, which I traced to the presence of incorrect /*@__PURE__*/ annotations in the index.js built by cm-buildhelper, one of which results in a crucial method call being stripped by Terser. Rather than rewrite perfectly valid code to work around it, I've instead added an option to omit the /*@__PURE__*/ annotations here. I admit I'm not sure what the consequences are for tree-shaking in this case, if any.

Adds `--source-map` and `--disable-pure-annotations` command line options to cm-buildhelper. We're using https://github.com/replit/codemirror-emacs and found it not working correctly in production mode, which I traced to the presence of incorrect `/*@__PURE__*/` annotations in the index.js built by cm-buildhelper, one of which results in a crucial method call being stripped by Terser. Rather than rewrite perfectly valid code to work around it, I've instead added an option to omit the `/*@__PURE__*/` annotations here. I admit I'm not sure what the consequences are for tree-shaking in this case, if any.
marijnh commented 2022-07-12 08:43:52 +02:00 (Migrated from github.com)

Does using @marijn/buildtool instead of @codemirror/buildhelper (which is a special-purpose tool for building the core CodeMirror packages, not intended to be flexible) work for you?

Does using [@marijn/buildtool](https://www.npmjs.com/package/@marijn/buildtool) instead of @codemirror/buildhelper (which is a special-purpose tool for building the core CodeMirror packages, not intended to be flexible) work for you?
timdown commented 2022-07-12 11:58:29 +02:00 (Migrated from github.com)

This looks perfect, thank you. I didn't know this existed.

However, I'm seeing an error. I have a very simple build script, bin/build.js:

#!/usr/bin/env node

import { build } from '@marijn/buildtool'

build('src/index.ts', { pureTopCalls: false }).then(result => {
    if (!result) process.exit(1)
})

In src/index.ts, the first line is

import { BlockCursorPlugin, hideNativeSelection } from "./block-cursor"

... which imports src/block-cursor.ts. However, running build.js gives me the following error:

Error: Could not resolve './block-cursor' from src/index.js

Changing the import in index.js to "../src/block-cursor" fixes it.

Is there something awry in these lines https://github.com/marijnh/buildtool/blob/main/src/buildtool.ts#L174-L179 or am I just being stupid (a distinct possibility)? I am confused because this bit of code looks identical to the equivalent bit in @codemirror/buildhelper, which works, at least when I use it via cm-buildhelper.

This looks perfect, thank you. I didn't know this existed. However, I'm seeing an error. I have a very simple build script, `bin/build.js`: ``` #!/usr/bin/env node import { build } from '@marijn/buildtool' build('src/index.ts', { pureTopCalls: false }).then(result => { if (!result) process.exit(1) }) ``` In `src/index.ts`, the first line is `import { BlockCursorPlugin, hideNativeSelection } from "./block-cursor"` ... which imports `src/block-cursor.ts`. However, running `build.js` gives me the following error: `Error: Could not resolve './block-cursor' from src/index.js` Changing the import in index.js to `"../src/block-cursor"` fixes it. Is there something awry in these lines https://github.com/marijnh/buildtool/blob/main/src/buildtool.ts#L174-L179 or am I just being stupid (a distinct possibility)? I am confused because this bit of code looks identical to the equivalent bit in @codemirror/buildhelper, which works, at least when I use it via `cm-buildhelper`.
timdown commented 2022-07-12 14:51:48 +02:00 (Migrated from github.com)

Ah, all is well if I pass an absolute path into build(), so I'm guessing that's the intention.

Ah, all is well if I pass an absolute path into `build()`, so I'm guessing that's the intention.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
codemirror/buildhelper!6
No description provided.