From fc42bfa7b67795785afa0e51fb817a537c20e430 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nacho=20Codo=C3=B1er?= Date: Thu, 23 May 2024 18:03:28 +0200 Subject: [PATCH 01/10] implement reset db option and default without cleaning db --- tools/cli/commands.js | 51 ++++++++++++++++++++++++++++++------------- tools/fs/files.ts | 8 +++++-- 2 files changed, 42 insertions(+), 17 deletions(-) diff --git a/tools/cli/commands.js b/tools/cli/commands.js index 4d5076ff33..32c39b3a86 100644 --- a/tools/cli/commands.js +++ b/tools/cli/commands.js @@ -1731,11 +1731,14 @@ main.registerCommand({ // Doesn't actually take an argument, but we want to print an custom // error message if they try to pass one. maxArgs: 1, + options: { + db: { type: Boolean }, + }, requiresApp: true, catalogRefresh: new catalog.Refresh.Never() }, async function (options) { if (options.args.length !== 0) { - Console.error("meteor reset only affects the locally stored database."); + Console.error("meteor reset might delete the local database using the --db option."); Console.error(); Console.error("To reset a deployed application use"); Console.error( @@ -1752,22 +1755,40 @@ main.registerCommand({ "MONGO_URL will NOT be reset."); } - // XXX detect the case where Meteor is running the app, but - // MONGO_URL was set, so we don't see a Mongo process - var findMongoPort = require('../runners/run-mongo.js').findMongoPort; - var isRunning = !! await findMongoPort(files.pathJoin(options.appDir, ".meteor", "local", "db")); - if (isRunning) { - Console.error("reset: Meteor is running."); - Console.error(); - Console.error( - "This command does not work while Meteor is running your application.", - "Exit the running Meteor development server."); - return 1; + if (options.db) { + // XXX detect the case where Meteor is running the app, but + // MONGO_URL was set, so we don't see a Mongo process + var findMongoPort = require('../runners/run-mongo.js').findMongoPort; + var isRunning = !! await findMongoPort(files.pathJoin(options.appDir, ".meteor", "local", "db")); + if (isRunning) { + Console.error("reset: Meteor is running."); + Console.error(); + Console.error( + "This command does not work while Meteor is running your application.", + "Exit the running Meteor development server."); + return 1; + } + + return files.rm_recursive_async( + files.pathJoin(options.appDir, '.meteor', 'local') + ).then(() => { + Console.info("Project reset."); + }); } - return files.rm_recursive_async( - files.pathJoin(options.appDir, '.meteor', 'local') - ).then(() => { + var allExceptDb = files.getPathsInDir(files.pathJoin('.meteor', 'local'), { + cwd: options.appDir, + maxDepth: 1, + }).filter(function (path) { + return !path.includes('.meteor/local/db'); + }); + + var allRemovePromises = allExceptDb.map(_path => files.rm_recursive_async( + files.pathJoin(options.appDir, _path) + )); + console.log("-> allRemovePromises", allRemovePromises); + + Promise.all(allRemovePromises).then(() => { Console.info("Project reset."); }); }); diff --git a/tools/fs/files.ts b/tools/fs/files.ts index 57633fc698..ef1a5fd1c1 100644 --- a/tools/fs/files.ts +++ b/tools/fs/files.ts @@ -600,6 +600,7 @@ Profile("files.symlinkWithOverwrite", async function symlinkWithOverwrite( export function getPathsInDir(dir: string, options: { cwd?: string; output?: string[]; + maxDepth?: number; }) { // Don't let this function yield so that the file system doesn't get changed // underneath us @@ -619,6 +620,7 @@ export function getPathsInDir(dir: string, options: { } const output = options.output || []; + const maxDepth = options.maxDepth; function pathIsDirectory(path: string) { var stat = lstat(path); @@ -631,10 +633,12 @@ export function getPathsInDir(dir: string, options: { output.push(newPath); - if (pathIsDirectory(newAbsPath)) { + const nextMaxDepth = maxDepth != null ? maxDepth - 1 : maxDepth; + if (pathIsDirectory(newAbsPath) && (nextMaxDepth == null || nextMaxDepth > 0)) { getPathsInDir(newPath, { cwd: cwd, - output: output + output: output, + ...nextMaxDepth != null && { maxDepth: nextMaxDepth }, }); } }); From 92c0026d357c0fcad9953bebc9495b9f3539ccb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nacho=20Codo=C3=B1er?= Date: Mon, 27 May 2024 15:48:07 +0200 Subject: [PATCH 02/10] make sure --db is cleaned properly on test required --- tools/tests/mongo.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/tests/mongo.js b/tools/tests/mongo.js index d90e6925d1..53fcccf128 100644 --- a/tools/tests/mongo.js +++ b/tools/tests/mongo.js @@ -86,7 +86,7 @@ selftest.define("mongo with multiple --port numbers (#7563)", async function () } // Make absolutely sure we're creating the database for the first time. - await check(["reset"], ["Project reset."]); + await check(["reset", "--db"], ["Project reset."]); let count = 0; function next() { From eddd9ca0f7b1cdcf36e1862cd42b29ca9d71aee5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nacho=20Codo=C3=B1er?= Date: Mon, 27 May 2024 15:51:17 +0200 Subject: [PATCH 03/10] improve help text --- tools/cli/help.txt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/cli/help.txt b/tools/cli/help.txt index 1eff3661b6..42a0d1975e 100644 --- a/tools/cli/help.txt +++ b/tools/cli/help.txt @@ -500,11 +500,12 @@ development database. The current working directory must be a Meteor project directory, and the Meteor application must already be running. >>> reset -Reset the project state. Erases the local database. -Usage: meteor reset +Reset the project state. +Usage: meteor reset [--db] -Reset the current project to a fresh state. Removes all local data. +Reset the current project to a fresh state and clears the local cache. +The --db flag also removes the local database. >>> deploy Deploy this project to Galaxy, Meteor's hosting service. From 0fd3d09d15da7c50e93a5c04f62445370eb9e296 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nacho=20Codo=C3=B1er?= Date: Mon, 27 May 2024 16:00:59 +0200 Subject: [PATCH 04/10] fix latest issues with new reset cmd and db option --- tools/cli/commands.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/tools/cli/commands.js b/tools/cli/commands.js index 32c39b3a86..c63d517ba6 100644 --- a/tools/cli/commands.js +++ b/tools/cli/commands.js @@ -1769,11 +1769,11 @@ main.registerCommand({ return 1; } - return files.rm_recursive_async( + await files.rm_recursive_async( files.pathJoin(options.appDir, '.meteor', 'local') - ).then(() => { - Console.info("Project reset."); - }); + ); + Console.info("Project reset."); + return; } var allExceptDb = files.getPathsInDir(files.pathJoin('.meteor', 'local'), { @@ -1786,11 +1786,8 @@ main.registerCommand({ var allRemovePromises = allExceptDb.map(_path => files.rm_recursive_async( files.pathJoin(options.appDir, _path) )); - console.log("-> allRemovePromises", allRemovePromises); - - Promise.all(allRemovePromises).then(() => { - Console.info("Project reset."); - }); + await Promise.all(allRemovePromises); + Console.info("Project reset."); }); /////////////////////////////////////////////////////////////////////////////// From 9027a4bf6140bd944e2bc75cf6552034ec59c8fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nacho=20Codo=C3=B1er?= Date: Mon, 27 May 2024 16:07:53 +0200 Subject: [PATCH 05/10] update v3 docs --- tools/cli/help.txt | 2 +- v3-docs/docs/cli/index.md | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/cli/help.txt b/tools/cli/help.txt index 42a0d1975e..20d5dc5f84 100644 --- a/tools/cli/help.txt +++ b/tools/cli/help.txt @@ -503,7 +503,7 @@ project directory, and the Meteor application must already be running. Reset the project state. Usage: meteor reset [--db] -Reset the current project to a fresh state and clears the local cache. +Reset the current project to a fresh state and clear the local cache. The --db flag also removes the local database. diff --git a/v3-docs/docs/cli/index.md b/v3-docs/docs/cli/index.md index 40ecd77a1a..8cdcb64636 100644 --- a/v3-docs/docs/cli/index.md +++ b/v3-docs/docs/cli/index.md @@ -788,11 +788,12 @@ with `meteor run`. This will be easier in the future. ## meteor reset {meteorreset} -Reset the current project to a fresh state. Removes the local -mongo database. +Reset the current project to a fresh state and clear the local cache. + +To remove also the local mongo database use `--db` flag. ::: warning -This deletes your data! Make sure you do not have any information you +Reset with `--db` flag deletes your data! Make sure you do not have any information you care about in your local mongo database by running `meteor mongo`. From the mongo shell, use `show collections` and db.collection.find() to inspect your data. From 0f8a8f4acf278e94fc0d8933f01099ecac946283 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nacho=20Codo=C3=B1er?= Date: Mon, 27 May 2024 16:39:06 +0200 Subject: [PATCH 06/10] test coverage on reset command --- tools/tests/reset.js | 35 +++++++++++++++++++++++++++++++++++ tools/tool-testing/sandbox.js | 12 ++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 tools/tests/reset.js diff --git a/tools/tests/reset.js b/tools/tests/reset.js new file mode 100644 index 0000000000..e39371395d --- /dev/null +++ b/tools/tests/reset.js @@ -0,0 +1,35 @@ +var selftest = require('../tool-testing/selftest.js'); +var Sandbox = selftest.Sandbox; + +selftest.define("reset - clean cache vs database", async function () { + var s = new Sandbox(); + await s.init(); + + function shouldIncludeDb(sandbox, only) { + var cacheFiles = sandbox.readDir('.meteor/local'); + if (!cacheFiles) return false; + if (!only) return cacheFiles.includes('db'); + return cacheFiles.length === 1 && cacheFiles.includes('db'); + } + + var run; + + await s.createApp("myresetapp", "standard-app"); + s.cd("myresetapp"); + selftest.expectTrue(!shouldIncludeDb(s)); + + run = s.run("run"); + await run.read("=> Started MongoDB", false); + selftest.expectTrue(shouldIncludeDb(s)); + await run.stop(); + + run = s.run("reset"); + run.waitSecs(5); + await run.expectExit(0); + selftest.expectTrue(shouldIncludeDb(s, true)); + + run = s.run("reset", "--db"); + run.waitSecs(5); + await run.expectExit(0); + selftest.expectTrue(!shouldIncludeDb(s)); +}); diff --git a/tools/tool-testing/sandbox.js b/tools/tool-testing/sandbox.js index fed8a17c51..6a44de1530 100644 --- a/tools/tool-testing/sandbox.js +++ b/tools/tool-testing/sandbox.js @@ -316,6 +316,18 @@ export default class Sandbox { } } + // Reads a dir in the sandbox. 'filepath' is a + // path interpreted relative to the Sandbox's cwd. Returns null if + // dir does not exist. + readDir(filepath) { + const file = files.pathJoin(this.cwd, filepath); + if (!files.exists(file)) { + return null; + } else { + return files.readdir(files.pathJoin(this.cwd, filepath), 'utf8'); + } + } + // Copy the contents of one file to another. In these series of tests, we often // want to switch contents of package.js files. It is more legible to copy in // the backup file rather than trying to write into it manually. From a32fb3d8ba4a59cedd2dd103c7dccf54340f5289 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nacho=20Codo=C3=B1er?= Date: Mon, 27 May 2024 16:55:20 +0200 Subject: [PATCH 07/10] report breaking change on migration guide --- v3-docs/v3-migration-docs/breaking-changes/index.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/v3-docs/v3-migration-docs/breaking-changes/index.md b/v3-docs/v3-migration-docs/breaking-changes/index.md index 8141bac412..292bd823a8 100644 --- a/v3-docs/v3-migration-docs/breaking-changes/index.md +++ b/v3-docs/v3-migration-docs/breaking-changes/index.md @@ -22,6 +22,8 @@ const doc = await MyCollection.findOneAsync({ _id: '123' }); // [!code highlight ## CLI +### vue2 + The `--vue2` flag is no longer available. We droped support for vue2. You can see more information in this [PR](https://github.com/meteor/meteor/pull/13065). @@ -30,6 +32,13 @@ You can see more information in this [PR](https://github.com/meteor/meteor/pull/ This was decided because vue2 reached its [end of life](https://v2.vuejs.org/lts/#:~:text=Vue%202%20will%20reach%20End%20of%20Life%20(EOL)%20on%20December%2031st%2C%202023.%20After%20that%20date%2C%20Vue%202%20will%20continue%20to%20be%20available%20in%20all%20existing%20distribution%20channels%20(CDNs%20and%20package%20managers)%2C%20but%20will%20no%20longer%20receive%20updates%2C%20including%20security%20and%20browser%20compatibility%20fixes.) on 2023-12-31, the team decided to drop support for it. +### reset + +The `meteor reset` command clears only the local cache by default. Using the `--db` option will also delete the local Mongo database. Ensure your CI flows accommodate any changes by passing the `--db` option if needed. + +#### Why? + +This command is often recommended to fix your development project by clearing the cache. Previously, it also cleared the local MongoDB, which could accidentally delete important data. ## Node v20 @@ -272,4 +281,3 @@ const user = Meteor.user(); // [!code error] const user = await Meteor.userAsync(); // [!code highlight] ``` - From 415e030c3a25340d56d2469f53580489a7010862 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nacho=20Codo=C3=B1er?= Date: Mon, 27 May 2024 16:57:38 +0200 Subject: [PATCH 08/10] update migration guide --- guide/source/3.0-migration.md | 2 +- v3-docs/v3-migration-docs/index.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/guide/source/3.0-migration.md b/guide/source/3.0-migration.md index 8fefd8ae46..677f6be88b 100644 --- a/guide/source/3.0-migration.md +++ b/guide/source/3.0-migration.md @@ -137,7 +137,7 @@ You can update your Meteor 2.x project by running the command below inside your ```bash meteor update --release 3.0-rc.2 -meteor reset #resets local DB and project to a fresh state +meteor reset #resets project to a fresh state ``` ### When will Meteor 3.0 be ready? diff --git a/v3-docs/v3-migration-docs/index.md b/v3-docs/v3-migration-docs/index.md index b558c4b641..ce9c1e7294 100644 --- a/v3-docs/v3-migration-docs/index.md +++ b/v3-docs/v3-migration-docs/index.md @@ -29,7 +29,7 @@ You can upgrade your Meteor 2.x project by running the command below inside your ```bash meteor update --release 3.0-rc.2 -meteor reset #resets local DB and project to a fresh state +meteor reset #resets project to a fresh state ``` Also, it's a good idea to completely remove `node_modules` and the `package-lock.json` before running `meteor npm install`: From 00fdd5fbb971add118d5f0cae657894cde24d46f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nacho=20Codo=C3=B1er?= Date: Tue, 28 May 2024 14:13:14 +0200 Subject: [PATCH 09/10] add a warning on use reset --db on upgrade to meteor 3.0 --- v3-docs/v3-migration-docs/index.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/v3-docs/v3-migration-docs/index.md b/v3-docs/v3-migration-docs/index.md index ce9c1e7294..263affb732 100644 --- a/v3-docs/v3-migration-docs/index.md +++ b/v3-docs/v3-migration-docs/index.md @@ -29,7 +29,13 @@ You can upgrade your Meteor 2.x project by running the command below inside your ```bash meteor update --release 3.0-rc.2 -meteor reset #resets project to a fresh state +meteor reset # resets project to a fresh state +``` + +If you are upgrade from an older version of Meteor, you might have a different MongoDB driver version. If you encounter issues, consider clearing the local database. + +```bash +meteor reset --db # resets local db ``` Also, it's a good idea to completely remove `node_modules` and the `package-lock.json` before running `meteor npm install`: From 0ae603b9c7a0f79f8013152cb4b1f35c93458ef0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nacho=20Codo=C3=B1er?= Date: Tue, 28 May 2024 15:57:24 +0200 Subject: [PATCH 10/10] change logs on reset cmd --- tools/cli/commands.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/cli/commands.js b/tools/cli/commands.js index c63d517ba6..471a8baaae 100644 --- a/tools/cli/commands.js +++ b/tools/cli/commands.js @@ -1738,7 +1738,11 @@ main.registerCommand({ catalogRefresh: new catalog.Refresh.Never() }, async function (options) { if (options.args.length !== 0) { - Console.error("meteor reset might delete the local database using the --db option."); + Console.error("'meteor reset' command only affects the local project cache."); + Console.error(); + Console.error("To remove also the local database use"); + Console.error( + Console.command("meteor reset --db"), Console.options({ indent: 2 })); Console.error(); Console.error("To reset a deployed application use"); Console.error(