Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix auto-import #380

Merged
merged 2 commits into from
Dec 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
!*.json
!*.js
!*.ts
*.d.ts
!*.tsx
!src/plugin
!examples
Expand Down
12 changes: 10 additions & 2 deletions build-packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,24 @@ function createPackageFromFile(file, prefix, subfolder) {

const packageJSON = JSON.stringify(
{
internal: true,
name: name.toLowerCase(),
private: true,
main: `${prefix}lib/cjs/${subfolder}${name}.js`,
module: `${prefix}lib/esm/${subfolder}${name}.js`,
types: `${prefix}lib/esm/${subfolder}${name}.d.ts`,
types: `${prefix}${subfolder}${name}.d.ts`,
},
undefined,
2
)

fs.writeFileSync(`${subfolder}${name}/package.json`, packageJSON)

// It seems that VSCode and IDEs using auto-import are referenced by where the
// types are. So moving the types to the root fix the auto-imports.
fs.renameSync(
`./types/${subfolder}${name}.d.ts`,
`./${subfolder}${name}.d.ts`
)
}

function createPackagesFromFolder(folder, prefix, subfolder = '') {
Expand Down
23 changes: 12 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "next-translate",
"version": "1.0.0-canary.6",
"version": "1.0.0-canary.7",
"description": "Tiny and powerful i18n tools (Next plugin + API) to translate your Next.js pages.",
"license": "MIT",
"keywords": [
Expand Down Expand Up @@ -28,23 +28,24 @@
},
"main": "./lib/cjs/index.js",
"module": "./lib/esm/index.js",
"types": "./lib/esm/index.d.ts",
"types": "./index.d.ts",
"files": [
"cli",
"lib",
"plugin",
"appWithI18n",
"DynamicNamespaces",
"I18nProvider",
"loadNamespaces",
"Trans",
"withTranslation",
"useTranslation"
"plugin*",
"appWithI18n*",
"DynamicNamespaces*",
"I18nProvider*",
"loadNamespaces*",
"Trans*",
"withTranslation*",
"useTranslation*",
"index*"
],
"scripts": {
"build": "yarn clean && cross-env NODE_ENV=production && yarn tsc",
"clean": "yarn clean:build && yarn clean:examples",
"clean:build": "rm -rf lib plugin appWith* Dynamic* I18n* index _context loadNa* Trans useT* withT* getP*",
"clean:build": "rm -rf lib plugin appWith* Dynamic* I18n* index _context loadNa* Trans useT* withT* getP* *.d.ts types",
"clean:examples": "rm -rf examples/**/.next && rm -rf examples/**/node_modules && rm -rf examples/**/yarn.lock",
"example": "yarn example:complex",
"example:basic": "yarn build && cd examples/basic && yarn && yarn dev",
Expand Down
3 changes: 2 additions & 1 deletion tsconfig-cjs.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"compilerOptions": {
"module": "CommonJS",
"outDir": "./lib/cjs",
"declaration": false
"declaration": false,
"declarationDir": null
}
}
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"declaration": true,
"lib": ["esnext", "dom"],
"forceConsistentCasingInFileNames": true,
"outDir": "./lib/esm"
"outDir": "./lib/esm",
"declarationDir": "./types"
},
"include": ["./src"]
}