@mpfrontend/workspace-config 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,58 @@
1
+ import { dirname, posix, resolve, sep } from 'node:path';
2
+ /** Folders whose units are imported from outside only through their `index.ts`. */
3
+ const unitFolders = ['features', 'entities'];
4
+ /** `/x/src/features/orders/ui/view.tsx` -> `{kind: 'features', unit: '/x/src/features/orders', rest: 'ui/view.tsx'}`. */
5
+ export function unitOf(path) {
6
+ const parts = path.split('/');
7
+ for (let index = parts.length - 3; index >= 0; index--) {
8
+ if (parts[index] !== 'src' || !unitFolders.includes(parts[index + 1]) || !parts[index + 2])
9
+ continue;
10
+ return { kind: parts[index + 1], unit: parts.slice(0, index + 3).join('/'), rest: parts.slice(index + 3).join('/') };
11
+ }
12
+ return undefined;
13
+ }
14
+ /** The public entry is the unit folder itself or its index module, with or without an extension. */
15
+ function isEntry(rest) {
16
+ return rest === '' || /^index(?:\.(?:ts|tsx|js|mjs))?$/.test(rest);
17
+ }
18
+ const rule = {
19
+ meta: {
20
+ type: 'problem',
21
+ docs: { description: 'Import a feature or an entity from outside only through its index.ts public entry' },
22
+ schema: [],
23
+ messages: {
24
+ privateImport: "'{{source}}' reaches inside the {{kind}} unit '{{unit}}'; import its public entry " +
25
+ "'{{entry}}' instead, and export what you need from its index.ts.",
26
+ },
27
+ },
28
+ create(context) {
29
+ const filename = context.filename.split(sep).join('/');
30
+ const importer = unitOf(filename);
31
+ const check = (node, source) => {
32
+ if (typeof source !== 'string' || !source.startsWith('.'))
33
+ return;
34
+ const target = posix.normalize(resolve(dirname(filename), source).split(sep).join('/'));
35
+ const unit = unitOf(target);
36
+ if (!unit || isEntry(unit.rest) || importer?.unit === unit.unit)
37
+ return;
38
+ const entry = posix.relative(posix.dirname(filename), unit.unit) || '.';
39
+ context.report({
40
+ node: node,
41
+ messageId: 'privateImport',
42
+ data: { source, kind: unit.kind === 'features' ? 'feature' : 'entity', unit: posix.basename(unit.unit), entry: entry.startsWith('.') ? entry : './' + entry },
43
+ });
44
+ };
45
+ return {
46
+ ImportDeclaration(node) { check(node, node.source?.value); },
47
+ ExportNamedDeclaration(node) { check(node, node.source?.value); },
48
+ ExportAllDeclaration(node) { check(node, node.source?.value); },
49
+ ImportExpression(node) {
50
+ const source = node.source;
51
+ if (source?.type === 'Literal')
52
+ check(node, source.value);
53
+ },
54
+ };
55
+ },
56
+ };
57
+ export default rule;
58
+ //# sourceMappingURL=public-entry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"public-entry.js","sourceRoot":"","sources":["../../src/rules/public-entry.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,EAAC,MAAM,WAAW,CAAC;AAIvD,mFAAmF;AACnF,MAAM,WAAW,GAAG,CAAC,UAAU,EAAE,UAAU,CAAU,CAAC;AAEtD,yHAAyH;AACzH,MAAM,UAAU,MAAM,CAAC,IAAY;IACjC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC9B,KAAK,IAAI,KAAK,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC;QACvD,IAAI,KAAK,CAAC,KAAK,CAAC,KAAK,KAAK,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAU,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC;YAAE,SAAS;QAC9G,OAAO,EAAC,IAAI,EAAE,KAAK,CAAC,KAAK,GAAG,CAAC,CAAE,EAAE,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,GA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AC,QAAQ,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC;YACxE,OAAO,CAAC,MAAM,CAAC;gBACb,IAAI,EAAE,IAAa;gBACnB,SAAS,EAAE,eAAe;gBAC1B,IAAI,EAAE,EAAC,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,KAAK,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,EAAE,IAAI,EAAE,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,GAAG,KAAK,EAAC;aAC5J,CAAC,CAAC;QACL,CAAC,CAAC;QACF,OAAO;YACL,iBAAiB,CAAC,IAAI,IAAI,KAAK,CAAC,IAAuB,EAAG,IAAwB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;YACpG,sBAAsB,CAAC,IAAI,IAAI,KAAK,CAAC,IAAuB,EAAG,IAAwB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;YACzG,oBAAoB,CAAC,IAAI,IAAI,KAAK,CAAC,IAAuB,EAAG,IAAwB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;YACvG,gBAAgB,CAAC,IAAI;gBACnB,MAAM,MAAM,GAAI,IAAwB,CAAC,MAAM,CAAC;gBAChD,IAAI,MAAM,EAAE,IAAI,KAAK,SAAS;oBAAE,KAAK,CAAC,IAAuB,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;YAC/E,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC;AACF,eAAe,IAAI,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,43 @@
1
1
  {
2
2
  "name": "@mpfrontend/workspace-config",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "license": "Apache-2.0",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/panahister/mpfrontend.git",
8
+ "directory": "packages/workspace-config"
9
+ },
10
+ "type": "module",
11
+ "exports": {
12
+ "./eslint": {
13
+ "types": "./dist/eslint.d.ts",
14
+ "import": "./dist/eslint.js"
15
+ },
16
+ "./prettier": {
17
+ "types": "./dist/prettier.d.ts",
18
+ "import": "./dist/prettier.js"
19
+ },
20
+ "./tsconfig/base.json": "./tsconfig/base.json",
21
+ "./tsconfig/next.json": "./tsconfig/next.json",
22
+ "./tsconfig/library.json": "./tsconfig/library.json"
23
+ },
24
+ "files": [
25
+ "dist",
26
+ "README.md",
27
+ "tsconfig"
28
+ ],
29
+ "publishConfig": {
30
+ "access": "public",
31
+ "provenance": true
32
+ },
33
+ "dependencies": {
34
+ "@eslint/css": "2.0.0",
35
+ "@nx/eslint-plugin": "23.2.1",
36
+ "typescript-eslint": "8.71.1"
37
+ },
38
+ "peerDependencies": {
39
+ "eslint": ">=10 <11",
40
+ "prettier": ">=3 <4",
41
+ "typescript": ">=5.9 <6"
42
+ }
6
43
  }
@@ -0,0 +1,12 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "compilerOptions": {
4
+ "target": "ES2022",
5
+ "strict": true,
6
+ "skipLibCheck": true,
7
+ "esModuleInterop": true,
8
+ "resolveJsonModule": true,
9
+ "isolatedModules": true,
10
+ "forceConsistentCasingInFileNames": true
11
+ }
12
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "extends": "./base.json",
4
+ "compilerOptions": {
5
+ "lib": ["dom", "dom.iterable", "es2023"],
6
+ "module": "esnext",
7
+ "moduleResolution": "bundler",
8
+ "jsx": "react-jsx",
9
+ "declaration": true
10
+ }
11
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "extends": "./base.json",
4
+ "compilerOptions": {
5
+ "lib": ["dom", "dom.iterable", "esnext"],
6
+ "allowJs": true,
7
+ "noEmit": true,
8
+ "module": "esnext",
9
+ "moduleResolution": "bundler",
10
+ "jsx": "react-jsx",
11
+ "incremental": true,
12
+ "plugins": [{ "name": "next" }]
13
+ }
14
+ }