@adonisjs/assembler 6.1.3-9 → 7.0.0-1

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.
@@ -3,10 +3,25 @@
3
3
  * Options needed to run a script file
4
4
  */
5
5
  export type RunOptions = {
6
+ /**
7
+ * Script to run
8
+ */
6
9
  script: string;
10
+ /**
11
+ * Arguments to pass to the script
12
+ */
7
13
  scriptArgs: string[];
14
+ /**
15
+ * Arguments to pass to NodeJS CLI
16
+ */
8
17
  nodeArgs: string[];
18
+ /**
19
+ * Standard input ouput stream options
20
+ */
9
21
  stdio?: 'pipe' | 'inherit';
22
+ /**
23
+ * Environment variables to pass to the child process
24
+ */
10
25
  env?: NodeJS.ProcessEnv;
11
26
  };
12
27
  /**
@@ -16,48 +31,117 @@ export type WatchOptions = {
16
31
  poll?: boolean;
17
32
  };
18
33
  /**
19
- * Meta file config defined in ".adonisrc.json" file
34
+ * Meta file config defined in "adonisrc.ts" file
20
35
  */
21
36
  export type MetaFile = {
22
37
  pattern: string;
23
38
  reloadServer: boolean;
24
39
  };
25
40
  /**
26
- * Test suite defined in ".adonisrc.json" file
41
+ * Test suite defined in "adonisrc.ts" file
27
42
  */
28
43
  export type Suite = {
29
- files: string[];
30
44
  name: string;
45
+ files: string | string[];
31
46
  };
32
47
  /**
33
48
  * Options accepted by assets bundler
34
49
  */
35
50
  export type AssetsBundlerOptions = {
36
- serve: false;
37
- args?: string[];
51
+ enabled: false;
38
52
  driver?: string;
39
53
  cmd?: string;
54
+ args?: string[];
40
55
  } | {
41
- serve: true;
42
- args: string[];
56
+ enabled: true;
43
57
  driver: string;
44
58
  cmd: string;
59
+ args: string[];
45
60
  };
46
61
  /**
47
- * Options accepted by the dev server
62
+ * Options accepted when starting the dev
63
+ * server
48
64
  */
49
65
  export type DevServerOptions = {
66
+ /**
67
+ * Arguments to pass to the "bin/server.js" file
68
+ * executed a child process
69
+ */
50
70
  scriptArgs: string[];
71
+ /**
72
+ * Arguments to pass to Node.js CLI when executing
73
+ * the "bin/server.js" file
74
+ */
51
75
  nodeArgs: string[];
76
+ /**
77
+ * Clear screen after every file change
78
+ */
52
79
  clearScreen?: boolean;
80
+ /**
81
+ * Environment variables to share with the "bin/server.js"
82
+ * file.
83
+ */
53
84
  env?: NodeJS.ProcessEnv;
85
+ /**
86
+ * An array of metaFiles glob patterns to watch
87
+ */
54
88
  metaFiles?: MetaFile[];
89
+ /**
90
+ * Assets bundler options to start its dev server
91
+ */
55
92
  assets?: AssetsBundlerOptions;
56
93
  };
57
94
  /**
58
95
  * Options accepted by the test runner
59
96
  */
60
97
  export type TestRunnerOptions = {
98
+ /**
99
+ * Arguments to pass to the "bin/server.js" file
100
+ * executed a child process
101
+ */
102
+ scriptArgs: string[];
103
+ /**
104
+ * Arguments to pass to Node.js CLI when executing
105
+ * the "bin/server.js" file
106
+ */
107
+ nodeArgs: string[];
108
+ /**
109
+ * Clear screen after every file change
110
+ */
111
+ clearScreen?: boolean;
112
+ /**
113
+ * Environment variables to share with the "bin/server.js"
114
+ * file.
115
+ */
116
+ env?: NodeJS.ProcessEnv;
117
+ /**
118
+ * An array of metaFiles glob patterns to watch
119
+ */
120
+ metaFiles?: MetaFile[];
121
+ /**
122
+ * Assets bundler options to start its dev server
123
+ */
124
+ assets?: AssetsBundlerOptions;
125
+ /**
126
+ * An array of suites for which to run tests
127
+ */
128
+ suites: Suite[];
129
+ /**
130
+ * Set the tests runner reporter via the CLI flag
131
+ */
132
+ reporters?: string[];
133
+ /**
134
+ * Set the tests global timeout via the CLI flag
135
+ */
136
+ timeout?: number;
137
+ /**
138
+ * Define retries via the CLI flag
139
+ */
140
+ retries?: number;
141
+ /**
142
+ * Run only failed tests
143
+ */
144
+ failed?: boolean;
61
145
  /**
62
146
  * Filter arguments are provided as a key-value
63
147
  * pair, so that we can mutate them (if needed)
@@ -68,24 +152,77 @@ export type TestRunnerOptions = {
68
152
  groups: string[];
69
153
  files: string[];
70
154
  tags: string[];
71
- ignoreTags: string[];
72
155
  }>;
73
- /**
74
- * All other tags are provided as a collection of
75
- * arguments
76
- */
77
- scriptArgs: string[];
78
- nodeArgs: string[];
79
- clearScreen?: boolean;
80
- env?: NodeJS.ProcessEnv;
81
- metaFiles?: MetaFile[];
82
- assets?: AssetsBundlerOptions;
83
- suites: Suite[];
84
156
  };
85
157
  /**
86
158
  * Options accepted by the project bundler
87
159
  */
88
160
  export type BundlerOptions = {
161
+ /**
162
+ * An array of metaFiles glob patterns to copy the
163
+ * files to the build folder
164
+ */
89
165
  metaFiles?: MetaFile[];
166
+ /**
167
+ * Assets bundler options to create the production build
168
+ * for assets
169
+ */
90
170
  assets?: AssetsBundlerOptions;
91
171
  };
172
+ /**
173
+ * Entry to add a middleware to a given middleware stack
174
+ * via the CodeTransformer
175
+ */
176
+ export type MiddlewareNode = {
177
+ /**
178
+ * If you are adding a named middleware, then you must
179
+ * define the name.
180
+ */
181
+ name?: string;
182
+ /**
183
+ * The path to the middleware file
184
+ *
185
+ * @example
186
+ * `@adonisjs/static/static_middleware`
187
+ * `#middlewares/silent_auth.js`
188
+ */
189
+ path: string;
190
+ /**
191
+ * The position to add the middleware. If `before`
192
+ * middleware will be added at the first position and
193
+ * therefore will be run before all others
194
+ *
195
+ * @default 'after'
196
+ */
197
+ position?: 'before' | 'after';
198
+ };
199
+ /**
200
+ * Policy node to be added to the list of policies.
201
+ */
202
+ export type BouncerPolicyNode = {
203
+ /**
204
+ * Policy name
205
+ */
206
+ name: string;
207
+ /**
208
+ * Policy import path
209
+ */
210
+ path: string;
211
+ };
212
+ /**
213
+ * Defines the structure of an environment variable validation
214
+ * definition
215
+ */
216
+ export type EnvValidationNode = {
217
+ /**
218
+ * Write a leading comment on top of your variables
219
+ */
220
+ leadingComment?: string;
221
+ /**
222
+ * A key-value pair of env variables and their validation
223
+ *
224
+ * @example
225
+ * MY_VAR: 'Env.schema.string.optional()'
226
+ */
227
+ variables: Record<string, string>;
228
+ };
package/package.json CHANGED
@@ -1,80 +1,88 @@
1
1
  {
2
2
  "name": "@adonisjs/assembler",
3
- "version": "6.1.3-9",
4
3
  "description": "Provides utilities to run AdonisJS development server and build project for production",
4
+ "version": "7.0.0-1",
5
+ "engines": {
6
+ "node": ">=18.16.0"
7
+ },
5
8
  "main": "build/index.js",
6
9
  "type": "module",
7
10
  "files": [
8
- "build/src",
9
- "build/index.d.ts",
10
- "build/index.js"
11
+ "build",
12
+ "!build/bin",
13
+ "!build/tests"
11
14
  ],
12
15
  "exports": {
13
16
  ".": "./build/index.js",
17
+ "./code_transformer": "./build/src/code_transformer/main.js",
14
18
  "./types": "./build/src/types.js"
15
19
  },
16
- "engines": {
17
- "node": ">=18.16.0"
18
- },
19
20
  "scripts": {
20
21
  "pretest": "npm run lint",
21
- "test": "cross-env NODE_DEBUG=chokidar:ts c8 npm run quick:test",
22
+ "test": "c8 npm run quick:test",
22
23
  "lint": "eslint . --ext=.ts",
23
24
  "clean": "del-cli build",
24
25
  "typecheck": "tsc --noEmit",
25
- "compile": "npm run lint && npm run clean && tsc",
26
+ "precompile": "npm run lint && npm run clean",
27
+ "compile": "tsup-node && tsc --emitDeclarationOnly --declaration",
26
28
  "build": "npm run compile",
27
29
  "release": "np",
28
30
  "version": "npm run build",
29
31
  "sync-labels": "github-label-sync --labels .github/labels.json adonisjs/assembler",
30
32
  "format": "prettier --write .",
31
33
  "prepublishOnly": "npm run build",
32
- "quick:test": "node --loader=ts-node/esm bin/test.ts"
34
+ "quick:test": "cross-env NODE_DEBUG=adonisjs:assembler node --enable-source-maps --loader=ts-node/esm bin/test.ts"
33
35
  },
34
- "keywords": [
35
- "adonisjs",
36
- "build",
37
- "ts"
38
- ],
39
- "author": "virk,adonisjs",
40
- "license": "MIT",
41
36
  "devDependencies": {
42
- "@adonisjs/eslint-config": "^1.1.7",
43
- "@adonisjs/prettier-config": "^1.1.7",
44
- "@adonisjs/tsconfig": "^1.1.7",
45
- "@commitlint/cli": "^17.6.6",
46
- "@commitlint/config-conventional": "^17.6.6",
47
- "@japa/assert": "^2.0.0-1",
48
- "@japa/file-system": "^2.0.0-1",
49
- "@japa/runner": "^3.0.0-3",
50
- "@swc/core": "^1.3.67",
51
- "@types/node": "^20.3.3",
52
- "@types/picomatch": "^2.3.0",
53
- "c8": "^8.0.0",
37
+ "@adonisjs/application": "^8.0.0-3",
38
+ "@adonisjs/eslint-config": "^1.2.0",
39
+ "@adonisjs/prettier-config": "^1.2.0",
40
+ "@adonisjs/tsconfig": "^1.2.0",
41
+ "@commitlint/cli": "^18.4.3",
42
+ "@commitlint/config-conventional": "^18.4.3",
43
+ "@japa/assert": "^2.1.0",
44
+ "@japa/file-system": "^2.1.0",
45
+ "@japa/runner": "^3.1.1",
46
+ "@japa/snapshot": "^2.0.4",
47
+ "@swc/core": "^1.3.101",
48
+ "@types/node": "^20.10.5",
49
+ "@types/picomatch": "^2.3.3",
50
+ "@types/pretty-hrtime": "^1.0.3",
51
+ "c8": "^8.0.1",
54
52
  "cross-env": "^7.0.3",
53
+ "dedent": "^1.5.1",
55
54
  "del-cli": "^5.0.0",
56
- "eslint": "^8.44.0",
55
+ "eslint": "^8.56.0",
57
56
  "github-label-sync": "^2.3.1",
58
57
  "husky": "^8.0.3",
59
- "np": "^8.0.4",
58
+ "np": "^9.2.0",
60
59
  "p-event": "^6.0.0",
61
- "prettier": "^2.8.8",
62
- "ts-node": "^10.9.1",
63
- "typescript": "^5.1.6"
60
+ "prettier": "^3.1.1",
61
+ "ts-node": "^10.9.2",
62
+ "tsup": "^8.0.1",
63
+ "typescript": "^5.3.3"
64
64
  },
65
65
  "dependencies": {
66
- "@adonisjs/env": "^4.2.0-3",
67
- "@poppinss/chokidar-ts": "^4.1.0-4",
68
- "@poppinss/cliui": "^6.1.1-3",
69
- "cpy": "^8.1.2",
70
- "execa": "^7.0.0",
66
+ "@adonisjs/env": "^4.2.0-7",
67
+ "@antfu/install-pkg": "^0.3.1",
68
+ "@poppinss/chokidar-ts": "^4.1.3",
69
+ "@poppinss/cliui": "^6.2.3",
70
+ "cpy": "^11.0.0",
71
+ "execa": "^8.0.1",
72
+ "fast-glob": "^3.3.2",
71
73
  "get-port": "^7.0.0",
72
- "picomatch": "^2.3.1",
73
- "slash": "^5.1.0"
74
+ "junk": "^4.0.1",
75
+ "picomatch": "^3.0.1",
76
+ "pretty-hrtime": "^1.0.3",
77
+ "slash": "^5.1.0",
78
+ "ts-morph": "^21.0.1"
74
79
  },
75
80
  "peerDependencies": {
76
81
  "typescript": "^4.0.0 || ^5.0.0"
77
82
  },
83
+ "author": "virk,adonisjs",
84
+ "license": "MIT",
85
+ "homepage": "https://github.com/adonisjs/assembler#readme",
78
86
  "repository": {
79
87
  "type": "git",
80
88
  "url": "git+ssh://git@github.com/adonisjs/assembler.git"
@@ -82,7 +90,15 @@
82
90
  "bugs": {
83
91
  "url": "https://github.com/adonisjs/assembler/issues"
84
92
  },
85
- "homepage": "https://github.com/adonisjs/assembler#readme",
93
+ "keywords": [
94
+ "adonisjs",
95
+ "build",
96
+ "ts"
97
+ ],
98
+ "eslintConfig": {
99
+ "extends": "@adonisjs/eslint-config/package"
100
+ },
101
+ "prettier": "@adonisjs/prettier-config",
86
102
  "commitlint": {
87
103
  "extends": [
88
104
  "@commitlint/config-conventional"
@@ -106,14 +122,24 @@
106
122
  "exclude": [
107
123
  "tests/**",
108
124
  "build/**",
125
+ "bin/**",
126
+ "tmp/**",
109
127
  "examples/**",
110
128
  "src/dev_server.ts",
111
129
  "src/test_runner.ts",
112
130
  "src/assets_dev_server.ts"
113
131
  ]
114
132
  },
115
- "eslintConfig": {
116
- "extends": "@adonisjs/eslint-config/package"
117
- },
118
- "prettier": "@adonisjs/prettier-config"
133
+ "tsup": {
134
+ "entry": [
135
+ "./index.ts",
136
+ "./src/code_transformer/main.ts"
137
+ ],
138
+ "outDir": "./build",
139
+ "clean": true,
140
+ "format": "esm",
141
+ "dts": false,
142
+ "sourcemap": true,
143
+ "target": "esnext"
144
+ }
119
145
  }
@@ -1,158 +0,0 @@
1
- /*
2
- * @adonisjs/core
3
- *
4
- * (c) AdonisJS
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
- import { cliui } from '@poppinss/cliui';
10
- import { run } from './helpers.js';
11
- /**
12
- * Instance of CLIUI
13
- */
14
- const ui = cliui();
15
- /**
16
- * Exposes the API to start the development server for processing assets during
17
- * development.
18
- *
19
- * - Here we are running the assets dev server in a child process.
20
- * - Piping the output from the child process and reformatting it before writing it to
21
- * process streams.
22
- *
23
- * AssetsDevServer is agnostic and can run any assets dev server. Be it Vite or Encore or
24
- * even Webpack directly.
25
- */
26
- export class AssetsDevServer {
27
- #cwd;
28
- #logger = ui.logger;
29
- #options;
30
- #devServer;
31
- /**
32
- * Getting reference to colors library from logger
33
- */
34
- get #colors() {
35
- return this.#logger.getColors();
36
- }
37
- constructor(cwd, options) {
38
- this.#cwd = cwd;
39
- this.#options = options;
40
- }
41
- /**
42
- * Logs messages from vite dev server stdout and stderr
43
- */
44
- #logViteDevServerMessage(data) {
45
- const dataString = data.toString();
46
- const lines = dataString.split('\n');
47
- /**
48
- * Logging VITE ready in message with proper
49
- * spaces and newlines
50
- */
51
- if (dataString.includes('ready in')) {
52
- console.log('');
53
- console.log(dataString.trim());
54
- return;
55
- }
56
- /**
57
- * Put a wrapper around vite network address log
58
- */
59
- if (dataString.includes('Local') && dataString.includes('Network')) {
60
- const sticker = ui.sticker().useColors(this.#colors).useRenderer(this.#logger.getRenderer());
61
- lines.forEach((line) => {
62
- if (line.trim()) {
63
- sticker.add(line);
64
- }
65
- });
66
- sticker.render();
67
- return;
68
- }
69
- /**
70
- * Log rest of the lines
71
- */
72
- lines.forEach((line) => {
73
- if (line.trim()) {
74
- console.log(line);
75
- }
76
- });
77
- }
78
- /**
79
- * Logs messages from assets dev server stdout and stderr
80
- */
81
- #logAssetsDevServerMessage(data) {
82
- const dataString = data.toString();
83
- const lines = dataString.split('\n');
84
- lines.forEach((line) => {
85
- if (line.trim()) {
86
- console.log(line);
87
- }
88
- });
89
- }
90
- /**
91
- * Set a custom CLI UI logger
92
- */
93
- setLogger(logger) {
94
- this.#logger = logger;
95
- return this;
96
- }
97
- /**
98
- * Starts the assets bundler server. The assets bundler server process is
99
- * considered as the secondary process and therefore we do not perform
100
- * any cleanup if it dies.
101
- */
102
- start() {
103
- if (!this.#options?.serve) {
104
- return;
105
- }
106
- this.#logger.info(`starting "${this.#options.driver}" dev server...`);
107
- /**
108
- * Create child process
109
- */
110
- this.#devServer = run(this.#cwd, {
111
- script: this.#options.cmd,
112
- /**
113
- * We do not inherit the stdio for vite and encore, because in
114
- * inherit mode they own the stdin and interrupts the
115
- * `Ctrl + C` command.
116
- */
117
- stdio: 'pipe',
118
- scriptArgs: this.#options.args,
119
- });
120
- /**
121
- * Log child process messages
122
- */
123
- this.#devServer.stdout?.on('data', (data) => {
124
- if (this.#options.driver === 'vite') {
125
- this.#logViteDevServerMessage(data);
126
- }
127
- else {
128
- this.#logAssetsDevServerMessage(data);
129
- }
130
- });
131
- this.#devServer.stderr?.on('data', (data) => {
132
- if (this.#options.driver === 'vite') {
133
- this.#logViteDevServerMessage(data);
134
- }
135
- else {
136
- this.#logAssetsDevServerMessage(data);
137
- }
138
- });
139
- this.#devServer
140
- .then((result) => {
141
- this.#logger.warning(`"${this.#options.driver}" dev server closed with status code "${result.exitCode}"`);
142
- })
143
- .catch((error) => {
144
- this.#logger.warning(`unable to connect to "${this.#options.driver}" dev server`);
145
- this.#logger.fatal(error);
146
- });
147
- }
148
- /**
149
- * Stop the dev server
150
- */
151
- stop() {
152
- if (this.#devServer) {
153
- this.#devServer.removeAllListeners();
154
- this.#devServer.kill('SIGKILL');
155
- this.#devServer = undefined;
156
- }
157
- }
158
- }