Skip to content

v0.32.0-alpha.1

Pre-release
Pre-release

Choose a tag to compare

@thescientist13 thescientist13 released this 09 Mar 01:19
· 194 commits to master since this release

Overview

This second release in the v0.32.0 release line introduces built-in TypeScript support for Greenwood, refines some of Greenwood's type definitions, frontmatter collections can now be an array, and fixes a couple of bugs.

NOTE: Please bump to v0.32.0-alpha.5 to get some small hot fixes with some of Greenwood's types

# npm
$ npm i -D @greenwood/cli@alpha

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

# pnpm
$ pnpm i -D @greenwood/cli@alpha

Changelog

https://github.com/ProjectEvergreen/greenwood/issues?q=label%3Av0.32.0-alpha.1

  1. Built-In TypeScript support
  2. support an array for collections frontmatter key
  3. bundled static assets from node_modules not getting uploaded to Cloudflare
  4. incomplete import map generation (when there are lots of dependencies)

Features (Early Access)

TypeScript

With this release, Greenwood now provides built-in support for TypeScript, with the ability to fallback to using tsc if certain TypeScript features you're using (like Decorators, enums, namespaces, etc) are not supported through just type stripping alone. Docs are still in progress for types and TypeScript, so please see the below references for now, and please feel free to ask in Discord if you have any questions / feedback if trying this stuff out early.

You can see some example repos here:

NodeJS Version

You'll need to use version >=22.6.0 and need to set the --experimental-strip-types flag for any Greenwood commands

{
  "scripts": {
    "build": "NODE_OPTIONS='--experimental-strip-types' greenwood build"
  }
}

If you're feeling adventurous, you can use >=23.x.x and omit the flag, and keep an eye on this PR for when unflagged typestripping support may come to Node LTS 22.x 👀

TypeScript

You'll need to install typescript into your project in devDependencies

$ npm i typescript --save-dev

Configuration File

You can now author your configuration file (and plugins) in TypeScript by having a greenwood.config.ts file

import type { Config } from '@greenwood/cli';

const config: Config = {
  // ...
}

export default config;

TypeScript Plugin

If you're using Greenwood's TypeScript plugin, you can remove that from your Greenwood configuration file (as it is now considered deprecated).

tsconfig.json

You'll need these minimum settings in your tsconfig.json for compilerOptions, but feel free to add your own on top. We also recommend adding "erasableSyntaxOnly": true.

{
  "compilerOptions": {
    "module": "preserve",
    "moduleResolution": "bundler",
    "allowImportingTsExtensions": true,
    "verbatimModuleSyntax": false,
    "noEmit": true
  }
}

Type Definitions

Below are some common type definitions you can add to your project based on what features / plugins you might be using with Greenwood.

// Greenwood Raw plugin
declare module "*?type=raw" {
  const content: string;
  export default content;
}

// Greenwood CSS Modules plugin
declare module "*.module.css" {
  const classes: { [key: string]: string };
  export default classes;
}

// CSS Import Attribute
// https://github.com/microsoft/TypeScript/issues/46135
declare module "*.css" {
  const sheet: CSSStyleSheet;

  export default sheet;
}

tsc Fallback

As mentioned, built-in type-stripping may not handle all TypeScript features, or even JavaScript features like Decorators. If that's the case, you can enable the useTsc flag in your configuration file to fallback to using tsc with the full power of the TypeScript compiler.

import type { Config } from '@greenwood/cli';

const config: Config = {
  useTsc: true
};

export default config;

Breaking Changes

TypeScript Plugin

Starting with this release, the TypeScript plugin is officially considered deprecated, so please follow the above steps for integrating built-in TypeScript support into your project. When the official v0.32.0 release goes out, the package will be deprecated on NPM.

Known Issues

  1. Plugin types are broken
  2. Excessive configuration file detected logs

Diff

v0.32.0-alpha.0...v0.32.0-alpha.1