Skip to content

Commit

Permalink
chore: use import subpath from package.json for internal imports
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalets committed Aug 27, 2024
1 parent d792807 commit eb0c954
Show file tree
Hide file tree
Showing 22 changed files with 91 additions and 44 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Dev
* update @cucumber/html-formatter ([#213](https://github.com/vitalets/playwright-bdd/issues/213))
* chore: use import subpath from package.json for internal imports

## 7.2.2
* fix: provide empty world for Playwright-style steps ([#208](https://github.com/vitalets/playwright-bdd/issues/208))
Expand Down
13 changes: 13 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ export default [
'no-empty-pattern': 0,
},
},
{
files: ['src/**/*.ts'],
rules: {
'no-restricted-imports': [
'error',
{
// restrict high parent imports in favor of import subpaths (not path alias!)
// https://www.typescriptlang.org/docs/handbook/modules/reference.html#packagejson-imports-and-self-name-imports
patterns: ['../../../*'],
},
],
},
},
{
files: ['test/**/*.{ts,js,mjs}'],
plugins: {
Expand Down
7 changes: 3 additions & 4 deletions knip.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ const config: KnipConfig = {
'src/index.ts',
'src/decorators.ts',
'src/reporter/cucumber/index.ts',
'scripts/**',
'examples/**',
'test/**',
],
project: ['src/**/*.ts'],
ignore: ['**/*.d.ts'],
ignore: ['**/*.d.ts', '**/.features-gen/**'],
ignoreBinaries: ['docsify'],
ignoreDependencies: [
'@cucumber/compatibility-kit',
'@cucumber/pretty-formatter',
'@types/react-dom',
'react-dom',
'lint-staged',
'np',
'npm-run-all',
Expand Down
32 changes: 27 additions & 5 deletions package-lock.json

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

10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
"./reporter/cucumber": "./dist/reporter/cucumber/index.js",
"./package.json": "./package.json"
},
"imports": {
"#*": {
"pw-bdd-dev": "./dist/src/*",
"default": "./dist/*"
}
},
"engines": {
"node": ">=18"
},
Expand All @@ -25,7 +31,7 @@
"prepare": "git config core.hooksPath .hooks",
"lint": "eslint .",
"tsc": "tsc",
"knip": "knip -c knip.config.mts",
"knip": "knip -c knip.config.mts --tsConfig tsconfig.build.json",
"prettier": "prettier --check --ignore-unknown .",
"prettier:w": "prettier --write --ignore-unknown .",
"test": "node test/setup.mjs && node --test test/**/test.mjs",
Expand Down Expand Up @@ -73,7 +79,7 @@
"eslint-plugin-playwright": "1.6.2",
"expect-type": "0.19.0",
"globals": "15.8.0",
"knip": "5.26.0",
"knip": "5.27.4",
"lint-staged": "15.2.7",
"lodash.get": "4.4.2",
"marked": "13.0.2",
Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Command } from 'commander';
import { ConfigOption } from '../options';
import { Logger } from '../../utils/logger';
import { getPackageVersion } from '../../utils';
import { resolveConfigFile } from '../../playwright/loadConfig';
import { resolveConfigFile } from '#playwright/loadConfig.js';
import { relativeToCwd } from '../../utils/paths';

const logger = new Logger({ verbose: true });
Expand Down
2 changes: 1 addition & 1 deletion src/reporter/cucumber/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import fs from 'node:fs';
import { Writable } from 'node:stream';
import { finished } from 'node:stream/promises';
import { EventEmitter } from 'node:events';
import EventDataCollector from '../../cucumber/formatter/EventDataCollector';
import EventDataCollector from '#cucumber/formatter/EventDataCollector.js';

export type InternalOptions = {
cwd: string;
Expand Down
6 changes: 3 additions & 3 deletions src/reporter/cucumber/messagesBuilder/AttachmentMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@
* 2.4 remove found attachment from attachments array
*/
import * as pw from '@playwright/test/reporter';
import { AutofillMap } from '../../../utils/AutofillMap';
import { AutofillMap } from '#utils/AutofillMap.js';
import { collectStepsWithCategory, getHooksRootPwStep } from './pwStepUtils';
import { PwAttachment } from '../../../playwright/types';
import { stripAnsiEscapes } from '../../../utils/stripAnsiEscapes';
import { PwAttachment } from '#playwright/types.js';
import { stripAnsiEscapes } from '#utils/stripAnsiEscapes.js';

export class AttachmentMapper {
private stepAttachments = new AutofillMap<pw.TestStep, PwAttachment[]>();
Expand Down
4 changes: 2 additions & 2 deletions src/reporter/cucumber/messagesBuilder/GherkinDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* Attaches extra fields (meta).
*/
import * as messages from '@cucumber/messages';
import { GherkinDocumentWithPickles } from '../../../features/load';
import { GherkinDocumentWithPickles } from '#features/load.js';
import { ConcreteEnvelope } from './types';
import { omit } from '../../../utils';
import { omit } from '#utils/index.js';
import { ProjectInfo, getFeatureUriWithProject } from './Projects';

type GherkinDocumentMeta = {
Expand Down
4 changes: 2 additions & 2 deletions src/reporter/cucumber/messagesBuilder/GherkinDocumentClone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* pickle IDs and pickle steps IDs.
*/
import { randomUUID } from 'node:crypto';
import { GherkinDocumentWithPickles, PickleWithLocation } from '../../../features/load';
import { AutofillMap } from '../../../utils/AutofillMap';
import { GherkinDocumentWithPickles, PickleWithLocation } from '#features/load.js';
import { AutofillMap } from '#utils/AutofillMap.js';

export class GherkinDocumentClone {
private oldNewIds = new AutofillMap<string, string>();
Expand Down
10 changes: 5 additions & 5 deletions src/reporter/cucumber/messagesBuilder/GherkinDocuments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
*/
import path from 'node:path';
import * as messages from '@cucumber/messages';
import { AutofillMap } from '../../../utils/AutofillMap';
import { AutofillMap } from '#utils/AutofillMap.js';
import { TestCaseRun } from './TestCaseRun';
import { FeaturesLoader, GherkinDocumentWithPickles } from '../../../features/load';
import { getPlaywrightConfigDir } from '../../../config/configDir';
import { FeaturesLoader, GherkinDocumentWithPickles } from '#features/load.js';
import { getPlaywrightConfigDir } from '#config/configDir.js';
import { ConcreteEnvelope } from './types';
import { GherkinDocumentClone } from './GherkinDocumentClone';
import { GherkinDocumentMessage } from './GherkinDocument';
import { ProjectInfo, getFeatureUriWithProject } from './Projects';
import { getEnvConfigs } from '../../../config/env';
import { LANG_EN } from '../../../config/lang';
import { getEnvConfigs } from '#config/env.js';
import { LANG_EN } from '#config/lang.js';

export class GherkinDocuments {
private featuresLoader = new FeaturesLoader();
Expand Down
2 changes: 1 addition & 1 deletion src/reporter/cucumber/messagesBuilder/Hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { randomUUID } from 'node:crypto';
import * as pw from '@playwright/test/reporter';
import * as messages from '@cucumber/messages';
import { getPlaywrightConfigDir } from '../../../config/configDir';
import { getPlaywrightConfigDir } from '#config/configDir.js';
import path from 'node:path';

export type HookType = 'before' | 'after';
Expand Down
2 changes: 1 addition & 1 deletion src/reporter/cucumber/messagesBuilder/Meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
import os from 'node:os';
import * as messages from '@cucumber/messages';
import { getPackageVersion } from '../../../utils';
import { getPackageVersion } from '#utils/index.js';

export class Meta {
buildMessage() {
Expand Down
4 changes: 2 additions & 2 deletions src/reporter/cucumber/messagesBuilder/Pickles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* Builds Pickle messages.
*/
import * as messages from '@cucumber/messages';
import { omit } from '../../../utils';
import { AutofillMap } from '../../../utils/AutofillMap';
import { omit } from '#utils/index.js';
import { AutofillMap } from '#utils/AutofillMap.js';
import { TestCase } from './TestCase';
import { ConcreteEnvelope } from './types';
import { getFeatureUriWithProject } from './Projects';
Expand Down
2 changes: 1 addition & 1 deletion src/reporter/cucumber/messagesBuilder/Projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* See: https://github.com/microsoft/playwright/issues/29841
*/
import * as pw from '@playwright/test/reporter';
import { AutofillMap } from '../../../utils/AutofillMap';
import { AutofillMap } from '#utils/AutofillMap.js';

export type ProjectInfo = {
projectName?: string;
Expand Down
6 changes: 3 additions & 3 deletions src/reporter/cucumber/messagesBuilder/TestCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
import * as messages from '@cucumber/messages';
import { TestCaseRun } from './TestCaseRun';
import { Hook, HookType } from './Hook';
import { GherkinDocumentWithPickles, PickleWithLocation } from '../../../features/load';
import { stringifyLocation } from '../../../utils';
import { GherkinDocumentWithPickles, PickleWithLocation } from '#features/load.js';
import { stringifyLocation } from '#utils/index.js';
import { ProjectInfo } from './Projects';
import { BddData } from '../../../run/bddAnnotation/types';
import { BddData } from '#run/bddAnnotation/types.js';

type HookWithStep = {
hook: Hook;
Expand Down
8 changes: 4 additions & 4 deletions src/reporter/cucumber/messagesBuilder/TestCaseRun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
*/
import * as pw from '@playwright/test/reporter';
import * as messages from '@cucumber/messages';
import { stringifyLocation } from '../../../utils';
import { stringifyLocation } from '#utils/index.js';
import { Hook, HookType } from './Hook';
import { TestCase } from './TestCase';
import { AutofillMap } from '../../../utils/AutofillMap';
import { AutofillMap } from '#utils/AutofillMap.js';
import { TestStepRun, TestStepRunEnvelope } from './TestStepRun';
import { toCucumberTimestamp } from './timing';
import { collectStepsWithCategory, isUnknownDuration } from './pwStepUtils';
import { AttachmentMapper } from './AttachmentMapper';
import { TestCaseRunHooks } from './TestCaseRunHooks';
import { ProjectInfo, getProjectInfo } from './Projects';
import { BddData, BddDataStep } from '../../../run/bddAnnotation/types';
import { getBddDataFromTest } from '../../../run/bddAnnotation';
import { BddData, BddDataStep } from '#run/bddAnnotation/types.js';
import { getBddDataFromTest } from '#run/bddAnnotation/index.js';

export type TestCaseRunEnvelope = TestStepRunEnvelope &
Pick<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import fs from 'node:fs';
import * as pw from '@playwright/test/reporter';
import * as messages from '@cucumber/messages';
import { TestCaseRun } from './TestCaseRun';
import { PwAttachment } from '../../../playwright/types';
import { PwAttachment } from '#playwright/types.js';
import path from 'node:path';

export class TestStepAttachments {
Expand Down
2 changes: 1 addition & 1 deletion src/reporter/cucumber/messagesBuilder/TestStepRun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
import * as pw from '@playwright/test/reporter';
import * as messages from '@cucumber/messages';
import { stripAnsiEscapes } from '../../../utils/stripAnsiEscapes';
import { stripAnsiEscapes } from '#utils/stripAnsiEscapes.js';
import { TestCaseRun } from './TestCaseRun';
import { toCucumberTimestamp } from './timing';
import { TestStepAttachments } from './TestStepAttachments';
Expand Down
6 changes: 3 additions & 3 deletions src/reporter/cucumber/messagesBuilder/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import { TestCase } from './TestCase';
import { Meta } from './Meta';
import { TimeMeasured, calcMinMaxByArray, toCucumberTimestamp } from './timing';
import EventEmitter from 'node:events';
import EventDataCollector from '../../../cucumber/formatter/EventDataCollector';
import EventDataCollector from '#cucumber/formatter/EventDataCollector.js';
import { Hook } from './Hook';
import { AutofillMap } from '../../../utils/AutofillMap';
import { AutofillMap } from '#utils/AutofillMap.js';
import { GherkinDocuments } from './GherkinDocuments';
import { Pickles } from './Pickles';
import { ConcreteEnvelope } from './types';
import { hasBddConfig } from '../../../config/env';
import { hasBddConfig } from '#config/env.js';

export class MessagesBuilder {
private report = {
Expand Down
1 change: 1 addition & 0 deletions tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"customConditions": [],
"noEmit": false,
"declaration": true,
"declarationMap": true,
Expand Down
9 changes: 7 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@
"useUnknownInCatchVariables": false,
"forceConsistentCasingInFileNames": true,
"skipLibCheck": true,
"resolvePackageJsonImports": true,
"rootDir": ".",
"outDir": "dist",
"customConditions": ["pw-bdd-dev"],
"noEmit": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"jsx": "react"
"jsx": "react-jsx"
},
"include": ["**/*.ts", "**/*.tsx", "knip.config.mts"]
"include": ["**/*.ts", "**/*.tsx", "**/*.mts"],
"exclude": ["test/types-non-strict"]
}

0 comments on commit eb0c954

Please sign in to comment.