embroider icon indicating copy to clipboard operation
embroider copied to clipboard

Convert @embroider/addon-dev to ESM

Open NullVoxPopuli opened this issue 2 years ago • 4 comments

  • Convert addon-dev to ESM ( 👈 you are here)
    • ended up being required due to how tsc forbids ESM (even await import) in CJS-output (and we compile with tsc)
      • this came up because fix-bad-declaration-output is ESM only
    • Compiled with SWC
    • Do we need to generate types for everything? I saw only types for template-colocation-plugin were exported
      • This'll be hard until the rest of the embroider packages are ESM, and we have a better way to provide "global types" for dependencies. For example, @embroider/core requres types for NestedHooks, beforeAll, etc, and those types don't exist in addon-dev -- nor do they make sense to exist. Maybe it makes more sense to get rid of those globals and define the types we need to use for those functions.
  • Add addon.glint() utility to help out in the v2 addon blueprint
    • remove double package.json#scripts entries managed by concurrently
    • better CLI output (two tools don't try to clear each other)
    • work-around a couple problems with Glint (gts extensions, etc)
  • Remove the sample files
    • with the package becoming type=module, the extensions needed to change / be consistent with type=module schemeing. I didn't see they were actually used though, so they've been removed.

NullVoxPopuli avatar Jan 23 '24 21:01 NullVoxPopuli

I think you could use dynamic import inside closeBundle to not be blocked on esm conversion:

oh! that's a good idea! I always forget that's a thing. been so long since I've actually had to worry about cjs :sweat_smile:

NullVoxPopuli avatar Jan 23 '24 22:01 NullVoxPopuli

Nevermind -- our build setup is removing all imports........... image

NullVoxPopuli avatar Jan 23 '24 22:01 NullVoxPopuli

Been trying a few different compilation techniques, and it seems that there is a lot of:

[!] SyntaxError: Named export 'readJsonSync' not found. The requested module 'fs-extra' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'fs-extra';
const { readJsonSync, writeJsonSync } = pkg;

style of errors, including from @embroider/core

NullVoxPopuli avatar Feb 09 '24 22:02 NullVoxPopuli

woah, it's green

NullVoxPopuli avatar Feb 12 '24 17:02 NullVoxPopuli