| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -950,6 +950,9 @@ in the `$schema` must be replaced with the version of Node.js you are using. | |||
| 950 | 950 | }, | |
| 951 | 951 | "testRunner": { | |
| 952 | 952 | "test-isolation": "process" | |
| 953 | + }, | ||
| 954 | + "watch": { | ||
| 955 | + "watch-preserve-output": true | ||
| 953 | 956 | } | |
| 954 | 957 | } | |
| 955 | 958 | ``` | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -725,6 +725,35 @@ | |||
| 725 | 725 | "type": "boolean" | |
| 726 | 726 | } | |
| 727 | 727 | } | |
| 728 | + }, | ||
| 729 | + "watch": { | ||
| 730 | + "type": "object", | ||
| 731 | + "additionalProperties": false, | ||
| 732 | + "properties": { | ||
| 733 | + "watch": { | ||
| 734 | + "type": "boolean" | ||
| 735 | + }, | ||
| 736 | + "watch-kill-signal": { | ||
| 737 | + "type": "string" | ||
| 738 | + }, | ||
| 739 | + "watch-path": { | ||
| 740 | + "oneOf": [ | ||
| 741 | + { | ||
| 742 | + "type": "string" | ||
| 743 | + }, | ||
| 744 | + { | ||
| 745 | + "items": { | ||
| 746 | + "type": "string", | ||
| 747 | + "minItems": 1 | ||
| 748 | + }, | ||
| 749 | + "type": "array" | ||
| 750 | + } | ||
| 751 | + ] | ||
| 752 | + }, | ||
| 753 | + "watch-preserve-output": { | ||
| 754 | + "type": "boolean" | ||
| 755 | + } | ||
| 756 | + } | ||
| 728 | 757 | } | |
| 729 | 758 | }, | |
| 730 | 759 | "type": "object" | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,7 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | const { | |
| 3 | 3 | ArrayPrototypeForEach, | |
| 4 | + ArrayPrototypeIncludes, | ||
| 4 | 5 | ArrayPrototypeJoin, | |
| 5 | 6 | ArrayPrototypeMap, | |
| 6 | 7 | ArrayPrototypePush, | |
@@ -17,7 +18,7 @@ const { | |||
| 17 | 18 | triggerUncaughtException, | |
| 18 | 19 | exitCodes: { kNoFailure }, | |
| 19 | 20 | } = internalBinding('errors'); | |
| 20 | - const { getOptionValue } = require('internal/options'); | ||
| 21 | + const { getOptionValue, getOptionsAsFlagsFromBinding } = require('internal/options'); | ||
| 21 | 22 | const { FilesWatcher } = require('internal/watch_mode/files_watcher'); | |
| 22 | 23 | const { green, blue, red, white, clear } = require('internal/util/colors'); | |
| 23 | 24 | const { convertToValidSignal } = require('internal/util'); | |
@@ -40,14 +41,14 @@ const kCommand = ArrayPrototypeSlice(process.argv, 1); | |||
| 40 | 41 | const kCommandStr = inspect(ArrayPrototypeJoin(kCommand, ' ')); | |
| 41 | 42 | ||
| 42 | 43 | const argsWithoutWatchOptions = []; | |
| 43 | - | ||
| 44 | - for (let i = 0; i < process.execArgv.length; i++) { | ||
| 45 | - const arg = process.execArgv[i]; | ||
| 44 | + const argsFromBinding = getOptionsAsFlagsFromBinding(); | ||
| 45 | + for (let i = 0; i < argsFromBinding.length; i++) { | ||
| 46 | + const arg = argsFromBinding[i]; | ||
| 46 | 47 | if (StringPrototypeStartsWith(arg, '--watch=')) { | |
| 47 | 48 | continue; | |
| 48 | 49 | } | |
| 49 | 50 | if (arg === '--watch') { | |
| 50 | - const nextArg = process.execArgv[i + 1]; | ||
| 51 | + const nextArg = argsFromBinding[i + 1]; | ||
| 51 | 52 | if (nextArg && nextArg[0] !== '-') { | |
| 52 | 53 | // If `--watch` doesn't include `=` and the next | |
| 53 | 54 | // argument is not a flag then it is interpreted as | |
@@ -66,6 +67,16 @@ for (let i = 0; i < process.execArgv.length; i++) { | |||
| 66 | 67 | } | |
| 67 | 68 | continue; | |
| 68 | 69 | } | |
| 70 | + if (StringPrototypeStartsWith(arg, '--experimental-config-file')) { | ||
| 71 | + if (!ArrayPrototypeIncludes(arg, '=')) { | ||
| 72 | + // Skip the flag and the next argument (the config file path) | ||
| 73 | + i++; | ||
| 74 | + } | ||
| 75 | + continue; | ||
| 76 | + } | ||
| 77 | + if (arg === '--experimental-default-config-file') { | ||
| 78 | + continue; | ||
| 79 | + } | ||
| 69 | 80 | ArrayPrototypePush(argsWithoutWatchOptions, arg); | |
| 70 | 81 | } | |
| 71 | 82 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -249,7 +249,7 @@ void EnvironmentOptions::CheckOptions(std::vector<std::string>* errors, | |||
| 249 | 249 | } else if (test_runner_force_exit) { | |
| 250 | 250 | errors->push_back("either --watch or --test-force-exit " | |
| 251 | 251 | "can be used, not both"); | |
| 252 | - } else if (!test_runner && (argv->size() < 1 || (*argv)[1].empty())) { | ||
| 252 | + } else if (!test_runner && watch_mode_paths.empty() && argv->size() < 1) { | ||
| 253 | 253 | errors->push_back("--watch requires specifying a file"); | |
| 254 | 254 | } | |
| 255 | 255 | ||
@@ -1011,20 +1011,26 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() { | |||
| 1011 | 1011 | AddOption("--watch", | |
| 1012 | 1012 | "run in watch mode", | |
| 1013 | 1013 | &EnvironmentOptions::watch_mode, | |
| 1014 | - kAllowedInEnvvar); | ||
| 1014 | + kAllowedInEnvvar, | ||
| 1015 | + false, | ||
| 1016 | + OptionNamespaces::kWatchNamespace); | ||
| 1015 | 1017 | AddOption("--watch-path", | |
| 1016 | 1018 | "path to watch", | |
| 1017 | 1019 | &EnvironmentOptions::watch_mode_paths, | |
| 1018 | - kAllowedInEnvvar); | ||
| 1020 | + kAllowedInEnvvar, | ||
| 1021 | + OptionNamespaces::kWatchNamespace); | ||
| 1019 | 1022 | AddOption("--watch-kill-signal", | |
| 1020 | 1023 | "kill signal to send to the process on watch mode restarts" | |
| 1021 | 1024 | "(default: SIGTERM)", | |
| 1022 | 1025 | &EnvironmentOptions::watch_mode_kill_signal, | |
| 1023 | - kAllowedInEnvvar); | ||
| 1026 | + kAllowedInEnvvar, | ||
| 1027 | + OptionNamespaces::kWatchNamespace); | ||
| 1024 | 1028 | AddOption("--watch-preserve-output", | |
| 1025 | 1029 | "preserve outputs on watch mode restart", | |
| 1026 | 1030 | &EnvironmentOptions::watch_mode_preserve_output, | |
| 1027 | - kAllowedInEnvvar); | ||
| 1031 | + kAllowedInEnvvar, | ||
| 1032 | + false, | ||
| 1033 | + OptionNamespaces::kWatchNamespace); | ||
| 1028 | 1034 | Implies("--watch-path", "--watch"); | |
| 1029 | 1035 | AddOption("--check", | |
| 1030 | 1036 | "syntax check script without executing", | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -412,7 +412,8 @@ std::vector<std::string> MapAvailableNamespaces(); | |||
| 412 | 412 | // Define all namespace entries | |
| 413 | 413 | #define OPTION_NAMESPACE_LIST(V) \ | |
| 414 | 414 | V(kNoNamespace, "") \ | |
| 415 | - V(kTestRunnerNamespace, "testRunner") | ||
| 415 | + V(kTestRunnerNamespace, "testRunner") \ | ||
| 416 | + V(kWatchNamespace, "watch") | ||
| 416 | 417 | ||
| 417 | 418 | enum class OptionNamespaces { | |
| 418 | 419 | #define V(name, _) name, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -791,4 +791,73 @@ process.on('message', (message) => { | |||
| 791 | 791 | `Completed running ${inspect(file)}. Waiting for file changes before restarting...`, | |
| 792 | 792 | ]); | |
| 793 | 793 | }); | |
| 794 | + | ||
| 795 | + it('should watch changes to a file from config file', async () => { | ||
| 796 | + const file = createTmpFile(); | ||
| 797 | + const configFile = createTmpFile(JSON.stringify({ watch: { 'watch': true } }), '.json'); | ||
| 798 | + const { stderr, stdout } = await runWriteSucceed({ | ||
| 799 | + file, watchedFile: file, args: ['--experimental-config-file', configFile, file], options: { | ||
| 800 | + timeout: 10000 | ||
| 801 | + } | ||
| 802 | + }); | ||
| 803 | + | ||
| 804 | + assert.strictEqual(stderr, ''); | ||
| 805 | + assert.deepStrictEqual(stdout, [ | ||
| 806 | + 'running', | ||
| 807 | + `Completed running ${inspect(file)}. Waiting for file changes before restarting...`, | ||
| 808 | + `Restarting ${inspect(file)}`, | ||
| 809 | + 'running', | ||
| 810 | + `Completed running ${inspect(file)}. Waiting for file changes before restarting...`, | ||
| 811 | + ]); | ||
| 812 | + }); | ||
| 813 | + | ||
| 814 | + it('should watch changes to a file with watch-path from config file', { | ||
| 815 | + skip: !supportsRecursive, | ||
| 816 | + }, async () => { | ||
| 817 | + const dir = tmpdir.resolve('subdir4'); | ||
| 818 | + mkdirSync(dir); | ||
| 819 | + const file = createTmpFile(); | ||
| 820 | + const watchedFile = createTmpFile('', '.js', dir); | ||
| 821 | + const configFile = createTmpFile(JSON.stringify({ watch: { 'watch-path': [dir] } }), '.json', dir); | ||
| 822 | + | ||
| 823 | + const args = ['--experimental-config-file', configFile, file]; | ||
| 824 | + const { stderr, stdout } = await runWriteSucceed({ file, watchedFile, args }); | ||
| 825 | + | ||
| 826 | + assert.strictEqual(stderr, ''); | ||
| 827 | + assert.deepStrictEqual(stdout, [ | ||
| 828 | + 'running', | ||
| 829 | + `Completed running ${inspect(file)}. Waiting for file changes before restarting...`, | ||
| 830 | + `Restarting ${inspect(file)}`, | ||
| 831 | + 'running', | ||
| 832 | + `Completed running ${inspect(file)}. Waiting for file changes before restarting...`, | ||
| 833 | + ]); | ||
| 834 | + assert.strictEqual(stderr, ''); | ||
| 835 | + }); | ||
| 836 | + | ||
| 837 | + it('should watch changes to a file from default config file', async () => { | ||
| 838 | + const dir = tmpdir.resolve('subdir5'); | ||
| 839 | + mkdirSync(dir); | ||
| 840 | + | ||
| 841 | + const file = createTmpFile('console.log("running");', '.js', dir); | ||
| 842 | + writeFileSync(path.join(dir, 'node.config.json'), JSON.stringify({ watch: { 'watch': true } })); | ||
| 843 | + | ||
| 844 | + const { stderr, stdout } = await runWriteSucceed({ | ||
| 845 | + file, | ||
| 846 | + watchedFile: file, | ||
| 847 | + args: ['--experimental-default-config-file', file], | ||
| 848 | + options: { | ||
| 849 | + timeout: 10000, | ||
| 850 | + cwd: dir | ||
| 851 | + } | ||
| 852 | + }); | ||
| 853 | + | ||
| 854 | + assert.strictEqual(stderr, ''); | ||
| 855 | + assert.deepStrictEqual(stdout, [ | ||
| 856 | + 'running', | ||
| 857 | + `Completed running ${inspect(file)}. Waiting for file changes before restarting...`, | ||
| 858 | + `Restarting ${inspect(file)}`, | ||
| 859 | + 'running', | ||
| 860 | + `Completed running ${inspect(file)}. Waiting for file changes before restarting...`, | ||
| 861 | + ]); | ||
| 862 | + }); | ||
| 794 | 863 | }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments