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

Set up NPM packaging as a private package #31

Merged
merged 3 commits into from
Feb 23, 2024
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
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ module.exports = {
"prettier.config.js",
"jest.config.js",
"public/**",
"build/**",
"dist/**",
"__mocks__/**",
"node_modules/**",
],
Expand Down
24 changes: 24 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages

name: Node.js Package

on:
release:
types: [published]

jobs:
publish-npm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ^20.4.0
registry-url: https://registry.npmjs.org/
- name: Yarn install
run: yarn install --ignore-engines --frozen-lockfile
- name: Publish npm package
run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_AUTH_TOKEN}}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,6 @@ dist
.pnp.*

build/

dist/

2 changes: 1 addition & 1 deletion p0
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ process.emit = function (name, data, ...args) {
return originalEmit.apply(process, arguments);
};

require(`${__dirname}/build/index.js`).main();
require(`${__dirname}/dist/index.js`).main();
28 changes: 20 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
{
"name": "p0cli",
"version": "0.2.0",
"name": "@komaldhull/p0cli",
"version": "0.2.5",
"description": "Execute infra CLI commands with P0 grants",
"main": "index.ts",
"repository": "https://github.com/p0-security/p0cli",
"repository": {
"type": "git",
"url": "git+https://github.com/p0-security/p0cli.git"
},
"author": "P0 Security",
"license": "Proprietary",
"private": true,
"license": "GPL-3.0-only",
"bin": {
"p0": "p0"
},
"files": [
"dist",
"p0",
"README.md",
"CONTRIBUTING.md"
],
"dependencies": {
"@rgrove/parse-xml": "^4.1.0",
"@types/pluralize": "^0.0.33",
Expand Down Expand Up @@ -42,8 +53,9 @@
"ts-jest": "^29.1.2"
},
"scripts": {
"build": "tsc && cp -r public build/",
"clean": "rm -rf build/",
"p0": "node --no-deprecation ./p0"
"build": "tsc && cp -r public dist/",
"clean": "rm tsconfig.tsbuildinfo && rm -rf dist/",
"p0": "node --no-deprecation ./p0",
"prepublishOnly": "npm run clean && npm run build"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the npm part is extraneous, as is the run:

Suggested change
"prepublishOnly": "npm run clean && npm run build"
"prepublishOnly": "clean && build"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried removing and it seems to be needed 🤷

}
}
3 changes: 1 addition & 2 deletions src/common/auth/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import express from "express";
import http from "node:http";
import { dirname } from "node:path";

const ROOT_PATH = dirname(require.main!.filename);
const ROOT_PATH = `${dirname(require.main!.filename)}/dist`;

/** A small amount of time is necessary prior to shutting down the redirect server to
* properly render the redirect-landing page
Expand Down Expand Up @@ -33,7 +33,6 @@ export const withRedirectServer = async <S, T, U>(
const token = req.query as T;
complete(value, token)
.then((result) => {
// res.redirect(`${ROOT_PATH}/redirect-landing.html`);
res.status(200).sendFile(`${ROOT_PATH}/public/redirect-landing.html`);
redirectResolve(result);
})
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
"outDir": "./build", /* Specify an output folder for all emitted files. */
"outDir": "./dist", /* Specify an output folder for all emitted files. */
// "removeComments": true, /* Disable emitting comments. */
// "noEmit": true, /* Disable emitting files from a compilation. */
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
Expand Down Expand Up @@ -104,5 +104,5 @@
"skipLibCheck": true /* Skip type checking all .d.ts files. */
},

"exclude": ["build/", "__mocks__/", "node_modules/"],
"exclude": ["dist/", "__mocks__/", "node_modules/"],
}
Loading