Wireit

repository·main·Indexed 27 days ago

https://github.com/google/wireit

A tool to upgrade npm scripts with dependency management, parallelism, and incremental builds via caching. Wireit integrates with package.json to provide features such as watch mode, clean builds, and support for long-running services, as well as local and GitHub Actions caching.

Tokens
7K
Snippets
16
Records
45
Agent score
92%

What's inside wireit

  1. Create a Personal Access Token (PAT) for publishing

    main

    To publish the extension to the Marketplace, you must create a Personal Access Token (PAT) in Azure DevOps with specific scopes:

    1. Visit https://dev.azure.com/polymer-vscode/_usersSettings/tokens.
    2. Click New Token.
    3. Set Name (e.g., "Publish Wireit VSCode extension").
    4. Set Organization to polymer-vscode.
    5. Set Expiration to Custom defined (e.g., 1 year).
    6. Set Scopes to Custom defined.
    7. Click Show all scopes.
    8. Scroll to Marketplace and check Manage.
    9. Click Create and securely save the resulting token.
  2. Enable script caching in Wireit

    main
    Wireit can skip running commands by copying output from a cache if the configuration and files haven't changed. To enable caching, you must define both the files and output arrays in your script configuration. For scripts that produce no files (like tests), set "output": [] to allow skipping tests if inputs remain unchanged.
  3. Configure input and output files for incremental builds

    main

    To enable features like Watch mode, Clean build, Incremental build, and Caching, you must define files (inputs) and output (outputs) using glob patterns in the wireit.<script> configuration.

    FeatureRequires filesRequires output
    Dependency graph--
    Watch mode☑️-
    Clean build-☑️
    Incremental build☑️☑️
    Caching☑️☑️

    Note: If a script has no files or output defined, it will always run. To tell Wireit it is safe to skip a script that has no inputs/outputs, set them to empty arrays: "files": [], "output": [].

    {
      "scripts": {
        "build": "wireit",
        "bundle": "wireit"
      },
      "wireit": {
        "build": {
          "command": "tsc",
          "files": ["src/**/*.ts", "tsconfig.json"],
          "output": ["lib/**"]
        },
        "bundle": {
          "command": "rollup -c",
          "dependencies": ["build"],
          "files": ["rollup.config.json"],
          "output": ["dist/bundle.js"]
        }
      }
    }
  4. Develop the Wireit VSCode extension locally

    main
    To build and install the extension into your local VSCode instance for development, use the install-extension script. If you want the extension to rebuild and reinstall automatically on every file change, use the --watch flag. Note that after a rebuild, you must run the Developer: Reload Window command within VSCode to apply the changes.
  5. Watch scripts with the --watch flag

    main
    You can automatically re-run any script configured with Wireit whenever changes are detected by appending the --watch flag to your execution command. For example, to watch your tests, use npm test --watch.
    npm test --watch
  6. Pass extra arguments to Wireit scripts

    main

    Use a double-dash -- to pass arguments through Wireit to the underlying command.

    Standard npm usage: npm run {script} {npm args} {wireit args} -- {script args}

    Example: npm run build -- --verbose

    Using node --run: node --run {script} {node args} -- {wireit args} -- {script args}

    npm run build -- --verbose
  7. Publish the Wireit VSCode extension

    main

    Follow these steps to prepare and publish a new version of the extension:

    1. Navigate to the extension directory: cd wireit/vscode-extension.
    2. Increment the version number in built/package.json following semver.
    3. Update CHANGELOG.md with the release notes.
    4. Build the extension: npm run package.
    5. Verify the build locally: npm run install-extension, reload VSCode, and perform manual testing.
    6. Submit a PR with the version and changelog updates, then merge to main.
    7. Log in to the VS Code Marketplace: npx vsce login google (use your PAT when prompted).
    8. Publish the extension using the built .vsix file: npx vsce publish -i built/wireit.vsix.
    cd wireit/vscode-extension
    # ... (edit built/package.json and CHANGELOG.md) ...
    npm run package
    npm run install-extension
    # ... (merge PR to main) ...
    npx vsce login google
    npx vsce publish -i built/wireit.vsix
  8. Configure local and GitHub Actions caching

    main

    Local Caching

    Local caching stores files in the .wireit folder within each package. It is enabled by default unless the CI=true environment variable is detected.

    • Force local caching: WIREIT_CACHE=local
    • Disable local caching: WIREIT_CACHE=none
    • To clear local cache: rm -rf .wireit/*/cache

    GitHub Actions Caching

    In GitHub Actions, Wireit uses the GitHub Actions cache service. To enable this, add the following uses clause to your workflow before your npm run or npm test commands:

    - uses: google/wireit@setup-github-actions-caching/v2
    # Example workflow snippet
    - uses: google/wireit@setup-github-actions-caching/v2
    
    - run: npm ci
    - run: npm test
  9. Check Wireit requirements and compatibility

    main

    Before using Wireit, ensure your environment meets the following requirements:

    • Operating Systems: Linux, macOS, and Windows.
    • Node.js: Version 18 or higher.
    • Script Runners: Wireit scripts can be executed via npm, node --run, pnpm, and yarn.
  10. Use wireit VSCode extension features

    main

    The extension provides several productivity features for managing wireit configurations in package.json:

    • Autocompletion: Get suggestions for properties within your wireit configuration.
    • Hover Documentation: View documentation for wireit properties by hovering over them.
    • Diagnostics: Receive instant highlighting of common mistakes in your configuration.
    • Jump to Definition:
      • Navigate directly to the definition of a dependency.
      • Jump from a script definition to its corresponding wireit configuration.
    • Code Actions:
      • Refactor: Automatically convert a vanilla npm script into a wireit script.
      • Quick Fixes: Apply suggested fixes for common configuration errors.