Skip to content

refactor: shared package #1030

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

Closed
wants to merge 4 commits into from
Closed
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
21 changes: 21 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
],
"dependencies": {
"@readme/api-core": "file:../core",
"@readme/api-shared": "file:../shared",
"chalk": "^5.3.0",
"ci-info": "^4.0.0",
"commander": "^14.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/bin.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { logger } from '@readme/api-shared';
import { Command } from 'commander';
import updateNotifier from 'update-notifier';

import commands from './commands/index.js';
import logger from './logger.js';
import * as pkg from './packageInfo.js'; // eslint-disable-line readme/no-wildcard-imports

updateNotifier({ pkg: { name: pkg.PACKAGE_NAME, version: pkg.PACKAGE_VERSION } }).notify();
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/codegen/languages/typescript/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import type { JsonObject, PackageJson, TsConfigJson } from 'type-fest';
import path from 'node:path';

import corePkg from '@readme/api-core/package.json' with { type: 'json' };
import { logger } from '@readme/api-shared';
import { execa } from 'execa';
import { getLicense } from 'license';
import { setWith } from 'lodash-es';
Expand All @@ -28,7 +29,6 @@ import semver from 'semver';
import { IndentationText, Project, QuoteKind, ScriptTarget, VariableDeclarationKind } from 'ts-morph';

import { buildCodeSnippetForOperation, getSuggestedOperation } from '../../../lib/suggestedOperations.js';
import logger from '../../../logger.js';
import { PACKAGE_VERSION } from '../../../packageInfo.js';
import Storage from '../../../storage.js';
import CodeGenerator from '../../codegenerator.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/commands/install.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { SupportedLanguage } from '../codegen/factory.js';

import { logger, oraOptions } from '@readme/api-shared';
import chalk from 'chalk';
import { Command, Option } from 'commander';
import { createEmphasize, common } from 'emphasize';
Expand All @@ -11,7 +12,6 @@ import uslug from 'uslug';
import { SupportedLanguages, codegenFactory } from '../codegen/factory.js';
import Fetcher from '../fetcher.js';
import promptTerminal from '../lib/prompt.js';
import logger, { oraOptions } from '../logger.js';
import Storage from '../storage.js';

const { highlight } = createEmphasize(common);
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/commands/list.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { logger } from '@readme/api-shared';
import chalk from 'chalk';
import { Command } from 'commander';

import { SupportedLanguages } from '../codegen/factory.js';
import logger from '../logger.js';
import Storage from '../storage.js';

const cmd = new Command();
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/commands/uninstall.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import path from 'node:path';

import { logger, oraOptions } from '@readme/api-shared';
import chalk from 'chalk';
import { Command, Option } from 'commander';
import ora from 'ora';

import { SupportedLanguages, uninstallerFactory } from '../codegen/factory.js';
import promptTerminal from '../lib/prompt.js';
import logger, { oraOptions } from '../logger.js';
import Storage from '../storage.js';

interface Options {
Expand Down
1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
},
"dependencies": {
"@readme/oas-to-har": "^26.0.0",
"@readme/api-shared": "file:../shared",
"caseless": "^0.12.0",
"datauri": "^4.1.0",
"fetch-har": "^11.0.1",
Expand Down
3 changes: 3 additions & 0 deletions packages/shared/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
coverage/
dist/
node_modules/
6 changes: 6 additions & 0 deletions packages/shared/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
coverage/
test/
.eslint*
.gitignore
.prettier*
vitest.*
44 changes: 44 additions & 0 deletions packages/shared/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "@readme/api-shared",
"version": "7.0.0-beta.14",
"description": "Common utilities and helpers shared between monorepo packages.",
"sideEffects": false,
"type": "module",
"exports": {
".": {
"require": "./dist/index.cjs",
"import": "./dist/index.js"
},
"./package.json": "./package.json"
},
"main": "dist/index.cjs",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"attw": "attw --pack --format ascii --profile node16",
"build": "tsup",
"prebuild": "rm -rf dist/",
"prepack": "npm run build"
},
"repository": {
"type": "git",
"url": "https://github.com/readmeio/api.git",
"directory": "packages/httpsnippet-client-api"
},
"bugs": {
"url": "https://github.com/readmeio/api/issues"
},
"author": "Andrii Andreiev <[email protected]>",
"license": "MIT",
"engines": {
"node": ">=20.10.0"
},
"dependencies": {
"ora": "^8.0.1",
"chalk": "^5.3.0"
},
"devDependencies": {
"typescript": "^5.8.2"
},
"prettier": "@readme/eslint-config/prettier"
}
3 changes: 3 additions & 0 deletions packages/shared/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { logger, oraOptions } from './logger.js';

export { logger, oraOptions };
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { Options as OraOptions } from 'ora';

import chalk from 'chalk';

export default function logger(log: string, error?: boolean) {
export function logger(log: string, error?: boolean) {
if (error) {
console.error(chalk.red(log));
} else {
Expand Down
8 changes: 8 additions & 0 deletions packages/shared/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"lib": ["DOM", "ES2023"],
"outDir": "dist/"
},
"include": ["./src/**/*"]
}
25 changes: 25 additions & 0 deletions packages/shared/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* eslint-disable import/no-extraneous-dependencies, node/no-extraneous-import */
import type { Options } from 'tsup';

import { defineConfig } from 'tsup';

// eslint-disable-next-line import/no-relative-packages
import config from '../../tsup.config.js';

export default defineConfig((options: Options) => ({
...options,
...config,

entry: ['src/index.ts'],

noExternal: [
// These dependencies are ESM-only but because we're building for ESM **and** CJS we can't
// treat them as external dependencies as CJS libraries can't load ESM code that uses `export`.
// `noExternal` will instead treeshake these dependencies down and include them in our compiled
// dists.
'camelcase',
'stringify-object',
],

silent: !options.watch,
}));