Skip to content

v0.31.0-alpha.0

Pre-release
Pre-release
Compare
Choose a tag to compare
@thescientist13 thescientist13 released this 02 Dec 19:57
· 20 commits to master since this release

Overview

This first pre-release in the v0.31.0 line introduces part 1 of an overhaul to how Greenwood generates import maps and resolves node_modules dependencies, to better support the entire exports spec as well as play nicer with a variety of package managers (like PNPM) and their various location strategies of where node_modules are installed on disk. In addition, these changes unlock more capabilities in import maps like referencing CSS files.

Be aware this is WIP and might break certain development and production build workflows, so please refrain from upgrading unless you are OK with testing and providing any compatibility feedback.

You can find the top-level tracking issue for this release here and if you have any questions, please feel free to reach out in Discord in the Greenwood #general channel.

To test the alpha, either manually bump all the versions in your package.json or you can use your package manager to upgrade each of your Greenwood dependencies to the alpha line (either way, all Greenwood dependencies need to be one the same version).

# npm
$ npm i @greenwood/cli@alpha

# Yarn 1.x (classic)
$ yarn upgrade @greenwood/cli@alpha

# pnpm
$ pnpm i @greenwood/cli@alpha

Changelog

https://github.com/ProjectEvergreen/greenwood/issues?q=label%3Av0.31.0+label%3Aalpha.0

  1. improve support for package.json exports when building up import maps
  2. leverage import.meta.resolve to support import maps generation and accurate node_modules resolution when building
  3. walk package error if @spectrum-web-components/action-menu is installed even if not used
  4. support non-JavaScript file formats for import maps
  5. Improve PNPM support
  6. Import Attributes support in Acorn
  7. not all expected modern JavaScript syntax supported

Breaking Changes

Import Maps (during development)

With this new version of Greenwood, our use of the exports spec will now be a lot more compliant and complete, but may (unintentionally) "break" some packages you are using. For example, Redux used to have NodeJS specific APIs in its client bundles, but as of the 5.x release, they now correctly segment browser from Node bundles using exports, which Greenwood will now honor.

If you find any issues after upgrading, please review any diagnostics emitted by Greenwood or check to see if there are newer versions of your package available.

process.env.NODE_ENV

Prior to this release, Greenwood had included a behavior that would automatically replace instances of process.env.NODE_ENV in browser build output, but this was mostly for libraries like Redux that were not properly isomorphic. (process is not supported in browsers!)

Ideally packages you use should acknowledge this already, but if you still run into packages that make this assumption, you can re-recreate this substitution behavior using a Greenwood plugin

// greenwood.config.js
import { ResourceInterface } from '@greenwood/cli/src/lib/resource-interface.js';

class ProcessEnvReplaceResource extends ResourceInterface {
  constructor(compilation) {
    super();

    this.compilation = compilation;
  }

  async shouldIntercept(url) {
    // your custom condition goes here
    return url.pathname.endsWith('redux.mjs');
  }

  async intercept(url, request, response) {
    const body = await response.text();
    const env = process.env.__GWD_COMMAND__ === 'develop' ? 'development' : 'production';
    const contents = body.replace(/process.env.NODE_ENV/g, `"${env}"`);

    return new Response(contents, {
      headers: new Headers({
        'Content-Type': 'text/javascript',
      })
    });
  }
}

export default {
  // ...
  plugins: [{
    type: 'resource',
    name: 'process-env-replace',
    provider: (compilation) => new ProcessEnvReplaceResource(compilation)
  }]
}

Known Issues

Import Maps (during development)

  1. Seeing an interesting diagnostic report worth investigating here - ProjectEvergreen/www.greenwoodjs.dev#146

PNPM

As acknowledged, this is a very preliminary alpha release and will require a follow up alpha release (alpha.1) to completely flesh out full support for PNPM to completely un-hardcode the assumed location of node_modules on disk which will likely impact your production builds at this time, so please reserve bug reports until after our next alpha release.

Diff

v0.30.2...v0.31.0-alpha.0