Skip to content

Instantly share code, notes, and snippets.

@aqzhyi
Last active December 17, 2024 21:40
Show Gist options
  • Save aqzhyi/71d208a0bd399087bdb328f85e38de74 to your computer and use it in GitHub Desktop.
Save aqzhyi/71d208a0bd399087bdb328f85e38de74 to your computer and use it in GitHub Desktop.
let's try the `copilot-instructions.md`

πŸ“– in node.js version 20 and above

πŸš₯ Rules

πŸš₯ when you need to resolve a file path, use fileURLToPath(new URL(relativePath), import.meta.url)

πŸš₯ when importing native node.js modules, use the node: protocol


πŸ“– in typescript and javascript

πŸš₯ Rules

  • πŸš₯ always use esm format (export/import) as the main module system, instead of amd and commonjs (cjs) code.

  • πŸš₯ the value of compiler.moduleResolution in the tsconfig.json file should be Bundler

    {
      "compilerOptions": {
    +   "moduleResolution": "Bundler",
      },
    }

πŸ“– in Git Commit Message

πŸš₯ Rules

πŸš₯ always use the "Angular Commit Format Reference Sheet" to write commit messages.


πŸ“– in package.json file

πŸš₯ Rules

πŸš₯ never add extra comments in the package.json file.

πŸš₯ if the "exports" field is a conditional reference, then:

Important

πŸ“£ you can consider using the command npx publint to check

also see https://github.com/bluwy/publint

  • always make sure that "types" is listed first (entry-point for TypeScript resolution - must occur first!)
  • always make sure that "default" is listed at the end (as generic fallback that always matches)

πŸ’‘ Tasks

πŸ’‘ if you say: refactor it to ESM module

  • there must be a type field, and its value should be "module".
  • remove the main, module, and types fields.
  • there must be an "exports" field.

for example:

{
+  "type": "module",
+  "exports": {
+    ".": {
+      "types": "./index.d.ts",
+      "import": "./index.mjs",
+      "default": "./index.cjs"
+    }
+  },
-  "main": "./index.cjs",
-  "module": "./index.mjs",
-  "types": "./index.d.ts",
}

πŸ’‘ if you say: refactor the order of the keys

  • just reorder the keys in the file, do not change the values of the keys

  • the order of the keys should be as follows:

    1. license
    2. private
    3. name
    4. version
    5. description
    6. files
    7. exports
    8. author
    9. repository
    10. homepage
    11. bugs
    12. peerDependencies
    13. dependencies
    14. devDependencies
    15. keywords
    16. scripts

πŸ“– in next@^15 with App-Router

πŸ’‘ Tasks

πŸ’‘ if you say: install chakra-ui@^3

Tip

also see chakra-ui get-started

  1. run in the terminal pnpm add @chakra-ui/react @emotion/react -S as dependencies

  2. run in the terminal pnpm add @chakra-ui/cli -D as devDependencies

  3. add the following script in package.json#scripts

    {
      "scripts": {
    +    "chakra": "chakra"
      }
    }
  4. find the <html></html> element in the ./app/layout.{tsx,jsx} file and add the suppressHydrationWarning attribute to it

    <html
      lang='en'
    + suppressHydrationWarning
    >

πŸ’‘ if you say: eject the default theme of chakra-ui@^3

  1. if the ./@chakra-ui/theme folder already exists, skip the steps below
  2. you run pnpm chakra eject --outdir @chakra-ui/theme in the project folder to create the default theme design and components

πŸ“– in astro@^4 and astro@^5

πŸš₯ Tasks

πŸš₯ if you say: refactor for @astrojs/ts-plugin

Tip

WHY?

The Astro TypeScript plugin can be installed separately when you are not using the official Astro VS Code extension. This plugin is automatically installed and configured by the VSCode extension, and you do not need to install both.

see https://docs.astro.build/en/guides/typescript/#typescript-editor-plugin

  • remove @astrojs/ts-plugin from the tsconfig.json file, for example:

    {
      "compilerOptions": {
        "baseUrl": ".",
        "plugins": [
    -     { "name": "@astrojs/ts-plugin" },
          { "name": "other-ts-plugin" }
        ]
      }
    }
  • remove @astrojs/ts-plugin from package.json dependencies

  • run pnpm remove @astrojs/ts-plugin in the terminal

πŸ“– Common Tasks

πŸš₯ Tasks

πŸš₯ if you say: auto load .env or install dotenv

please follow the steps below:

  1. add package dotenv to the devDependencies of package.json

    pnpm add dotenv -D
  2. introduce and call the dotenv.config() method where needed

    import 'dotenv/config'
  3. make sure the env.d.ts file exists. if it does not, create one in the ./app or ./src folder

  4. make sure env.d.ts is list in the include field of tsconfig.json

  5. make sure the env.d.ts has following code is there

    interface EnvVarables {
      // VITE_ENV_VARIABLE1: string
      // VITE_ENV_VARIABLE2: string
    }
    
    declare namespace NodeJS {
      interface ProcessEnv extends EnvVarables {}
    }
    
    interface ImportMeta {
      readonly env: EnvVarables
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment