David Zearing
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # RFC: Enforce consistency through package linting ## Problem When packages have assumptions about how they are consumed, or how they should be formatted, it makes them complicated to consume in a standard way. It is easy for developers to miss details when publishing their packages that make it hard to standardize consumption. Cloudpack is an effort to standardize providing on-demand es module bundles per npm package/version. These bundles can be consumed in the browser and can be serviced through an import-map service. For Cloudpack to create isolated bundles for any npm package, we need packages to follow a set of conformance rules: 1. They must include ES modules. (While CommonJS is supported for old node scenarios, it creates complexities for bundlers; cjs can't be tree shaken, and for isolated esm package bundling, cjs is not explicit about named exports and so we end up parsing the code to generate esm entry point stubs.) 2. They must be explicit about `sideEffects` in package.json. Without this, we can't tree shake bundles properly. 3. They must have no deep imports from other packages which aren't expressed as valid entries in `exports`. (Reaching into private things creates non-enforced contracts and leads to isolated bundles that contain duplicates of singletons.) 4. They must have no proprietary dependencies on bundler loaders which aren't supported. (but we can support a subset of standard import types like json, sass, css, txt, md, json, graphql) 5. They should be`isolatedModules` compliant. This is a TypeScript setting which indicates the package is built to be transpiled in isolation. (This implies they use `import type` and `export type` when dealing with types, and avoid using const enums.) 6. They should have TypeScript types referenced in the package.json. Otherwise they can't be consumed by other TypeScript libraries. 7. They should avoid using star exports from other libraries. Nested cross-package star exports are not preserved in either esbuild or webpack esm output. 9. They must follow semantic versioning (which should be enfored through api extractor in connection with beachball.) 10. Dependencies should be referenced correctly (caret deps) and precisely (all referenced packages listed, no additional unused packages listed.) Otherwise we are more likely pulling in duplicate dependencies. This list is non-exhaustive, yet we don't validate any of these today and have no common tooling to enforce these or to stage and fix new validation. When Microsoft produces packages which violate these rules, it pushes problems downstream, often manually mitigated or ignored. This creates numerous friction points without fixing root causes. The goal of this investigate is to address the root causes through common conformance validation. ## Assessing solutions Many of these issues really need to be validated after building, but before publishing. A project may have multiple build steps which do things like produce multiple module formats, generate stubs for proprietary import types, or roll the output up into a common file. We want validation to occur when these steps are completed, but before being published. That way we can ensure things can be consumed properly downstream. We don't want to overlap with existing tools. Some existing linting tools: * boll * npm-package-json-linter * eslint ## Ideas on how to address We need the ability to quickly iterate and update rules as we find problems. Today we have eslint, which can guard against code problems. For the remaining publishing issues, we have the following options: ### Idea 1: invent a specifically-scoped tool Ideally we have a cli tool hosted in the microsoft/1js-tools github repo which can be integrated in multiple build toolchains. This would enable us to use whatever we want under the hood; perhaps a combination of `npm-package-json-linter` and specific `eslint` rules would be used to validate the package. ### Idea 2: take over boll and repurpose specifically for pre-publishing validation Boll is an internal Microsoft project that loosely relates to the problem. The project lost ownership and momentum when the author left the company. Boll's current scope and future is murky at best. One idea would be to leverage the existing code and make it more focused to solve the pre-publishing concerns that can't be solved with eslint. Likely we'd rename, gut and repurpose it. This way existing projects using the current version/validation won't break. ### Idea 2: add to npm-package-json-lint ### Idea 3: fork npm-package-json-lint ## Reference: tooling evaluation ### npm-package-json-lint https://npmpackagejsonlint.org/ "A configurable linter for package.json files" https://github.com/tclindner/npm-package-json-lint/tree/master/src This tool helps validate package.json conformance, but is more of a glorified schema checker rather than a validator. For example, a "require-module" rule exists, but doesn't actually validate that the module is valid and points to esm. There's a "require-bugs" rule, but doesn't actually validate the url is valid and points to a github or vso repo. The project is in active development with the last checkin coming in 12 days ago. Source is built in JavaScript, rather than in TypeScript. Similar to eslint, requires a config which can extend a base, but you can override things. This means we can do things like change our base to require "bugs" be populated, and auto suppress the rule on tooling updates. Lots of rules available: ``` "require-author": "error", "require-description": "error", "require-engines": "error", "require-license": "error", "require-name": "error", "require-repository": "error", "require-version": "error", "require-bugs": "error", "require-homepage": "error", "require-keywords": "error", "bin-type": "error", "config-type": "error", "description-type": "error", "devDependencies-type": "error", "directories-type": "error", "engines-type": "error", "files-type": "error", "homepage-type": "error", "keywords-type": "error", "license-type": "error", "main-type": "error", "man-type": "error", "name-type": "error", "preferGlobal-type": "error", "private-type": "error", "repository-type": "error", "scripts-type": "error", "version-type": "error", ``` ### Boll Boll is a Microsoft tool used in Office, which lints a variety of things. It is unclear when Boll runs, but it seems to be at linting time, rather than post-install. It is also unclear what it is and isn't responsible for. The tool is built as a "catch all" linter, where some rules apply to the TypeScript (why not typescript-eslint?) and some rules apply to package.json (why not package-lint?) The project has ceased development as the primary author has left Microsoft and stopped contributing and managing the project. To gain a better understanding of its coverage, here are the rules it currently supports: - `CrossPackageDependencyDetector` - detects usage of files stored directly in other packages that happen to be in a known location on disk. (E.g. `import foo from '../../../../foo-package/lib/foo')`)` - `NodeModulesReferencesDetector` - detects imports to `node_modules` paths - `RedundantImportsDetector` - detects imports that are redundant. (Should be an eslint rule.) - `SrcDetector` - detects usage of `src` in import statements of TypeScript source files. (Seems to imply the tool runs on source code rather than published code.) - `TransitiveDependencyDetector` - detects imports to packages which aren't explicitly listed as dependencies within `package.json`. - `ESLintPreferConstRule` - ensures that the prefer-const eslint rule is enabled on all source file and that the rule is enabled as an error. (Why is this needed? What is special about this rule that requires another tool to validate it's on?) - `NoRedundantDepsRule` - ensures that peerDepenendecies in `package.json` aren't re-declared as regular dependencies. - `EnforceRationale` - ensures specific fields in package.json require a rationale for any additions. (Unclear how this works with `json` files that can't have comments.) - `PackageConsistency` ### npm-pkg-lint https://github.com/ext/npm-pkg-lint 2 stars, not used. Last code update a month ago, 1 contributor, written in TypeScript. However, there are good things about it to leverage: * disallowed files check (typescript config, unit tests, code coverage reports, test files, ci-related files). Should this just be an npmignore validator? * Missing files - verifies that entries in package.json actually exist. This is good. But doens't validate their validity * disallowed dependencies - verifies that common dev tools like eslint, typescript, etc are not listed as dependencies. Might be good, but even better would be to do something like complain about unused dependencies after attempting to bundle assets. If you include 'lodash' due to copy/paste but never use it, it's similar to the problem of including `typescript` in dependencies. * Shebang - validate bin files has `#/usr/bin/env node` at the beginning of a file * `package.json` fields - validates description, keywords, etc are present. Also enforces urls to be https, rather than http. * verify engine constraints - validates all transitive dependencies satisfy the node requirement. * @types/node and engine constraints - requires engines.node lowest major version is equal to `@types/node` major version. This is really smart.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully