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

Remove unused index.ts file at root of package #25

Merged
merged 2 commits into from
Apr 19, 2018

Conversation

cjlarose
Copy link
Contributor

@cjlarose cjlarose commented Mar 30, 2018

This causes compiler errors when trying to import the package in a typescript project

I describe this in better detail here: #23 (comment)

Closes #23

@cjlarose cjlarose force-pushed the remove-index-file branch from 52db687 to 6735fac Compare March 30, 2018 05:53
@jonathansant
Copy link

jonathansant commented Apr 2, 2018

This seems to resolve the issue. However, the index.d.ts is now in the dist folder after an npm pack. Consecutively, I had to add a /dist when importing the package:

import { Config } from "@kubernetes/client-node/dist";

Unless I'm missing something, the way to go is to copy the package.json to the dist directory and run the npm pack/publish within it. below is how I modified the package.json:

{
  "name": "@kubernetes/client-node",
  "version": "0.2.1",
  "description": "NodeJS client for kubernetes",
  "repository": {
    "type": "git",
    "url": "git+https://github.com/kubernetes-client/javascript.git"
  },
  "files": [
    "**/*.ts",
    "**/*.js"
  ],
  "main": "index.js",
  "types": "index.d.ts",
  "scripts": {
    "clean": "rm -Rf node_modules/ dist/",
    "build": "tsc && cp package.json dist/package.json",
    "test": "mocha -r ts-node/register src/**/*_test.ts"
  },
  "author": "Kubernetes Authors",
  "license": "Apache-2.0",
  "dependencies": {
    "base-64": "^0.1.0",
    "bluebird": "^3.3.5",
    "byline": "^5.0.0",
    "js-yaml": "^3.5.2",
    "jsonpath": "^0.2.11",
    "request": "^2.72.0",
    "shelljs": "^0.7.8 ",
    "underscore": "^1.8.3",
    "websocket": "^1.0.25"
  },
  "devDependencies": {
    "@types/base-64": "^0.1.2",
    "@types/bluebird": "^3.5.7",
    "@types/chai": "^4.0.1",
    "@types/js-yaml": "^3.5.31",
    "@types/mocha": "^2.2.41",
    "@types/node": "^8.0.2",
    "@types/underscore": "^1.8.1",
    "chai": "^4.0.2",
    "jasmine": "^2.8.0",
    "mocha": "^3.4.2",
    "ts-node": "^3.1.0",
    "typescript": "^2.3.4"
  },
  "bugs": {
    "url": "https://github.com/kubernetes-client/javascript/issues"
  },
  "homepage": "https://github.com/kubernetes-client/javascript#readme",
  "keywords": [
    "kubernetes",
    "client"
  ]
}

For this, to work we need to change the build project to run npm pack from the dist folder.

@cjlarose
Copy link
Contributor Author

cjlarose commented Apr 3, 2018

@jonathansant Thanks for looking into this! I think there's definitely something weird going on, but I don't think it's necessary to move the package.json into the dist directory because it's totally fine and normal for package.json to reference dist/index.js as the main module.

What I did instead is update the files key in package.json to reference the generated files with the correct path d5f18c0. If I run npm pack and examine the resulting package, I get a tree like

.
├── dist
│   ├── api.d.ts
│   ├── api.js
│   ├── attach.d.ts
│   ├── attach.js
│   ├── auth-wrapper.d.ts
│   ├── auth-wrapper.js
│   ├── config.d.ts
│   ├── config.js
│   ├── config_test.d.ts
│   ├── config_test.js
│   ├── config_types.d.ts
│   ├── config_types.js
│   ├── exec.d.ts
│   ├── exec.js
│   ├── index.d.ts
│   ├── index.js
│   ├── watch.d.ts
│   ├── watch.js
│   ├── web-socket-handler.d.ts
│   └── web-socket-handler.js
└── package.json

1 directory, 21 files

...which I think is totally normal.

When you use

import { Config } from "@kubernetes/client-node";

this should now correctly import Config from the main module (dist/index.js).

Please try it out and let me know if it works for you.

@abedra
Copy link

abedra commented Apr 3, 2018

I would love to see this get shipped soon if at all possible. I am currently up against the same issue. Is there a work around for the current release?

@cjlarose
Copy link
Contributor Author

cjlarose commented Apr 3, 2018

@abedra What I've been doing is just forking the repo and hosting the fixed version as a repo on github. npm allows you to install directly from Github repos.

I have an example here: https://github.com/cjlarose/javascript/tree/package

You can install with npm

npm install --save github:cjlarose/javascript#package

Though you'll probably want to make your own fork. My fork's got some stuff in it that might not get merged upstream.

@jonathansant
Copy link

@cjlarose sorry for the delayed response. I tried this and it worked just fine. I'm no authority over this repo but you can merge this PR. Thanks for your help.

@brendandburns
Copy link
Contributor

LGTM, thanks for the fix, will push this up soon.

@brendandburns brendandburns merged commit 534663f into kubernetes-client:master Apr 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants