@langri-sha/projen-lint-synthesized 0.1.1 → 0.2.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.
package/CHANGELOG.json CHANGED
@@ -2,7 +2,30 @@
2
2
  "name": "@langri-sha/projen-lint-synthesized",
3
3
  "entries": [
4
4
  {
5
- "date": "Wed, 01 May 2024 23:11:10 GMT",
5
+ "date": "Fri, 03 May 2024 10:44:32 GMT",
6
+ "version": "0.2.0",
7
+ "tag": "@langri-sha/projen-lint-synthesized_v0.2.0",
8
+ "comments": {
9
+ "patch": [
10
+ {
11
+ "author": "filip.dupanovic@gmail.com",
12
+ "package": "@langri-sha/projen-lint-synthesized",
13
+ "commit": "68e384490ef3496631d9e74f059a50a466179b5d",
14
+ "comment": "fix(workspace): Revise build command"
15
+ }
16
+ ],
17
+ "minor": [
18
+ {
19
+ "author": "filip.dupanovic@gmail.com",
20
+ "package": "@langri-sha/projen-lint-synthesized",
21
+ "commit": "976a3bb428390ade32e6a6a4332d335d4a39915b",
22
+ "comment": "feat(lint-synthesized): Configure package build"
23
+ }
24
+ ]
25
+ }
26
+ },
27
+ {
28
+ "date": "Wed, 01 May 2024 23:11:18 GMT",
6
29
  "version": "0.1.1",
7
30
  "tag": "@langri-sha/projen-lint-synthesized_v0.1.1",
8
31
  "comments": {
package/CHANGELOG.md CHANGED
@@ -1,12 +1,24 @@
1
1
  # Change Log - @langri-sha/projen-lint-synthesized
2
2
 
3
- This log was last generated on Wed, 01 May 2024 23:11:10 GMT and should not be manually modified.
3
+ This log was last generated on Fri, 03 May 2024 10:44:32 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## 0.2.0
8
+
9
+ Fri, 03 May 2024 10:44:32 GMT
10
+
11
+ ### Minor changes
12
+
13
+ - feat(lint-synthesized): Configure package build (filip.dupanovic@gmail.com)
14
+
15
+ ### Patches
16
+
17
+ - fix(workspace): Revise build command (filip.dupanovic@gmail.com)
18
+
7
19
  ## 0.1.1
8
20
 
9
- Wed, 01 May 2024 23:11:10 GMT
21
+ Wed, 01 May 2024 23:11:18 GMT
10
22
 
11
23
  ### Patches
12
24
 
package/lib/index.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ import { Component } from 'projen';
2
+ export interface LintSynthesizedOptions {
3
+ [pattern: string]: string | ((files: string[]) => string);
4
+ }
5
+ /**
6
+ * A component that lints synthesized files.
7
+ */
8
+ export declare class LintSynthesized extends Component {
9
+ #private;
10
+ constructor(scope: ConstructorParameters<typeof Component>[0], options?: LintSynthesizedOptions);
11
+ postSynthesize(): void;
12
+ }
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;AAUlC,MAAM,WAAW,sBAAsB;IACrC,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,MAAM,CAAC,CAAA;CAC1D;AAED;;GAEG;AACH,qBAAa,eAAgB,SAAQ,SAAS;;gBAI1C,KAAK,EAAE,qBAAqB,CAAC,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC,EACjD,OAAO,CAAC,EAAE,sBAAsB;IASzB,cAAc,IAAI,IAAI;CAsEhC"}
package/lib/index.js ADDED
@@ -0,0 +1,86 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _LintSynthesized_instances, _LintSynthesized_options, _LintSynthesized_run;
13
+ import { Component } from 'projen';
14
+ import createDebug from 'debug';
15
+ import * as fs from 'node:fs';
16
+ import { execaSync } from 'execa';
17
+ import { minimatch } from 'minimatch';
18
+ const debug = createDebug('projen-lint-synthesized');
19
+ /**
20
+ * A component that lints synthesized files.
21
+ */
22
+ export class LintSynthesized extends Component {
23
+ constructor(scope, options) {
24
+ super(scope, 'lint-synthesized');
25
+ _LintSynthesized_instances.add(this);
26
+ _LintSynthesized_options.set(this, void 0);
27
+ __classPrivateFieldSet(this, _LintSynthesized_options, options, "f");
28
+ debug('Initialized');
29
+ }
30
+ postSynthesize() {
31
+ super.postSynthesize();
32
+ debug('Commencing lints on synthesized files');
33
+ const fileInfo = Object.fromEntries(this.project.files
34
+ .filter((file) => fs.existsSync(file.absolutePath))
35
+ .map((file) => [
36
+ file.path,
37
+ {
38
+ file,
39
+ absolutePath: file.absolutePath,
40
+ mode: fs.statSync(file.absolutePath).mode,
41
+ },
42
+ ]));
43
+ const paths = Object.keys(fileInfo);
44
+ debug(`Found ${paths.length} synthesized files`);
45
+ const tasks = Object.entries(__classPrivateFieldGet(this, _LintSynthesized_options, "f") || {})
46
+ .map(([pattern, command]) => ({
47
+ pattern,
48
+ command,
49
+ files: minimatch.match(paths, pattern, { dot: true }),
50
+ }))
51
+ .filter(({ files }) => files.length);
52
+ for (const { files } of tasks) {
53
+ for (const file of files) {
54
+ const { absolutePath } = fileInfo[file];
55
+ fs.chmodSync(absolutePath, 0o755);
56
+ }
57
+ }
58
+ for (const { pattern, command, files } of tasks) {
59
+ debug(`Running command ${files.length} files matching pattern ${pattern}`);
60
+ try {
61
+ __classPrivateFieldGet(this, _LintSynthesized_instances, "m", _LintSynthesized_run).call(this, files, command);
62
+ }
63
+ catch {
64
+ // Let `execa` log errors.
65
+ }
66
+ }
67
+ for (const { files } of tasks) {
68
+ for (const file of files) {
69
+ const { absolutePath, mode } = fileInfo[file];
70
+ fs.chmodSync(absolutePath, mode);
71
+ }
72
+ }
73
+ }
74
+ }
75
+ _LintSynthesized_options = new WeakMap(), _LintSynthesized_instances = new WeakSet(), _LintSynthesized_run = function _LintSynthesized_run(files, command) {
76
+ const task = typeof command === 'string'
77
+ ? `${command} ${files.join(' ')}`
78
+ : command(files);
79
+ debug(`Running command ${task}`);
80
+ execaSync(task, {
81
+ shell: true,
82
+ stdio: 'inherit',
83
+ cwd: this.project.outdir,
84
+ });
85
+ };
86
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;AAClC,OAAO,WAAW,MAAM,OAAO,CAAA;AAE/B,OAAO,KAAK,EAAE,MAAM,SAAS,CAAA;AAE7B,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAErC,MAAM,KAAK,GAAG,WAAW,CAAC,yBAAyB,CAAC,CAAA;AAMpD;;GAEG;AACH,MAAM,OAAO,eAAgB,SAAQ,SAAS;IAG5C,YACE,KAAiD,EACjD,OAAgC;QAEhC,KAAK,CAAC,KAAK,EAAE,kBAAkB,CAAC,CAAA;;QANlC,2CAAiC;QAQ/B,uBAAA,IAAI,4BAAY,OAAO,MAAA,CAAA;QAEvB,KAAK,CAAC,aAAa,CAAC,CAAA;IACtB,CAAC;IAEQ,cAAc;QACrB,KAAK,CAAC,cAAc,EAAE,CAAA;QAEtB,KAAK,CAAC,uCAAuC,CAA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AAM,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,KAAK,EAAE,CAAC;YAChD,KAAK,CAAC,mBAAmB,KAAK,CAAC,MAAM,2BAA2B,OAAO,EAAE,CAAC,CAAA;YAE1E,IAAI,CAAC;gBACH,uBAAA,IAAI,wDAAK,MAAT,IAAI,EAAM,KAAK,EAAE,OAAO,CAAC,CAAA;YAC3B,CAAC;YAAC,MAAM,CAAC;gBACP,0BAA0B;YAC5B,CAAC;QACH,CAAC;QAED,KAAK,MAAM,EAAE,KAAK,EAAE,IAAI,KAAK,EAAE,CAAC;YAC9B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;gBACzB,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAA;gBAE7C,EAAE,CAAC,SAAS,CAAC,YAAY,EAAE,IAAI,CAAC,CAAA;YAClC,CAAC;QACH,CAAC;IACH,CAAC;CAgBF;2IAdM,KAAe,EAAE,OAA+C;IACnE,MAAM,IAAI,GACR,OAAO,OAAO,KAAK,QAAQ;QACzB,CAAC,CAAC,GAAG,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;QACjC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IAEpB,KAAK,CAAC,mBAAmB,IAAI,EAAE,CAAC,CAAA;IAEhC,SAAS,CAAC,IAAI,EAAE;QACd,KAAK,EAAE,IAAI;QACX,KAAK,EAAE,SAAS;QAChB,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM;KACzB,CAAC,CAAA;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "@langri-sha/projen-lint-synthesized",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
- "main": "src/index.ts",
6
+ "main": "dist/index.js",
7
7
  "dependencies": {
8
8
  "debug": "4.3.4",
9
9
  "minimatch": "9.0.4"
10
10
  },
11
11
  "devDependencies": {
12
- "@langri-sha/jest-test": "0.2.0",
13
- "@langri-sha/tsconfig": "0.2.0",
14
12
  "@types/debug": "4.1.12",
15
13
  "execa": "8.0.1",
16
14
  "prettier": "3.2.5",
17
- "projen": "0.81.1"
15
+ "projen": "0.81.1",
16
+ "@langri-sha/jest-test": "0.7.0",
17
+ "@langri-sha/tsconfig": "0.9.0"
18
18
  },
19
19
  "peerDependencies": {
20
20
  "projen": "^0.81.1",
@@ -22,5 +22,7 @@
22
22
  },
23
23
  "publishConfig": {
24
24
  "access": "public"
25
- }
26
- }
25
+ },
26
+ "scripts": {},
27
+ "types": "dist/index.d.ts"
28
+ }
@@ -1,23 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`defaults 1`] = `
4
- {
5
- ".gitignore": "# ~~ Generated by projen. To modify, edit .projenrc.js and run "npx projen".
6
- node_modules/
7
- !/.gitattributes
8
- !/.projen/tasks.json
9
- !/.projen/deps.json
10
- !/.projen/files.json
11
- ",
12
- ".projen/files.json": {
13
- "//": "~~ Generated by projen. To modify, edit .projenrc.js and run "npx projen".",
14
- "files": [
15
- ".gitattributes",
16
- ".gitignore",
17
- ".projen/deps.json",
18
- ".projen/files.json",
19
- ".projen/tasks.json",
20
- ],
21
- },
22
- }
23
- `;
package/src/index.test.ts DELETED
@@ -1,98 +0,0 @@
1
- import { directorySnapshot } from 'projen/lib/util/synth'
2
- import { expect, tempy, test } from '@langri-sha/jest-test'
3
-
4
- import { promises as fs } from 'node:fs'
5
- import path from 'node:path'
6
-
7
- import { Project, TextFile } from 'projen'
8
- import { LintSynthesized, type LintSynthesizedOptions } from './index'
9
-
10
- const setup = (options?: LintSynthesizedOptions) => {
11
- const outdir = tempy.directory()
12
-
13
- const project = new Project({
14
- name: 'test-project',
15
- outdir,
16
- })
17
-
18
- project.removeTask('build')
19
- project.removeTask('compile')
20
- project.removeTask('eject')
21
- project.removeTask('default')
22
- project.removeTask('package')
23
- project.removeTask('post-compile')
24
- project.removeTask('pre-compile')
25
- project.removeTask('test')
26
-
27
- new LintSynthesized(project, options)
28
-
29
- return { project }
30
- }
31
-
32
- test('defaults', () => {
33
- const { project } = setup()
34
-
35
- project.synth()
36
- expect(directorySnapshot(project.outdir)).toMatchSnapshot()
37
- })
38
-
39
- test('lints synthesized files', async () => {
40
- const { project } = setup({
41
- '*': 'prettier --ignore-unknown --write',
42
- })
43
-
44
- let file, contents
45
-
46
- file = new TextFile(project, 'test1.js')
47
- file.addLine(`module.exports = ${JSON.stringify({ foo: 'bar' })}`)
48
-
49
- file = new TextFile(project, 'test2.js')
50
- file.addLine(`module.exports = ${JSON.stringify({ foo: 'bar' })}`)
51
-
52
- project.synth()
53
-
54
- file = await fs.readFile(path.join(project.outdir, 'test1.js'))
55
- contents = file.toString('utf8')
56
-
57
- expect(contents).toEqual(`module.exports = { foo: "bar" };\n`)
58
-
59
- file = await fs.readFile(path.join(project.outdir, 'test2.js'))
60
- contents = file.toString('utf8')
61
-
62
- expect(contents).toEqual(`module.exports = { foo: "bar" };\n`)
63
- })
64
-
65
- test('lints hidden synthesized files', async () => {
66
- const { project } = setup({
67
- '*': 'prettier --ignore-unknown --write',
68
- })
69
-
70
- let file
71
-
72
- file = new TextFile(project, '.test.js')
73
- file.addLine(`module.exports = ${JSON.stringify({ foo: 'bar' })}`)
74
-
75
- project.synth()
76
-
77
- file = await fs.readFile(path.join(project.outdir, '.test.js'))
78
- const contents = file.toString('utf8')
79
-
80
- expect(contents).toEqual(`module.exports = { foo: "bar" };\n`)
81
- })
82
-
83
- test('preserves file modes', async () => {
84
- const { project } = setup({
85
- '*': 'prettier --ignore-unknown',
86
- })
87
-
88
- new TextFile(project, 'test.sh', {
89
- executable: true,
90
- readonly: true,
91
- })
92
-
93
- project.synth()
94
-
95
- await expect(
96
- fs.stat(path.join(project.outdir, 'test.sh')),
97
- ).resolves.toHaveProperty('mode', 33_124)
98
- })
package/tsconfig.json DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "$schema": "https://json.schemastore.org/tsconfig",
3
- "extends": "@langri-sha/tsconfig/project.json",
4
- "compilerOptions": {
5
- "baseUrl": ".",
6
- "outDir": ".tsbuild"
7
- },
8
- "references": [{ "path": "../jest-test" }, { "path": "../tsconfig" }]
9
- }