Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add downgrade script for algoliasearch v4 and steps #6286

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ workflows:
- unit tests:
requires:
- build
- legacy algoliasearch:
- legacy algoliasearch v3:
requires:
- build
- legacy algoliasearch v4:
requires:
- build
- vue v3:
Expand Down Expand Up @@ -97,7 +100,8 @@ workflows:
- lint
- unit tests
- examples
- legacy algoliasearch
- legacy algoliasearch v3
- legacy algoliasearch v4
- helper docs
- e2e tests
filters:
Expand Down Expand Up @@ -202,7 +206,7 @@ jobs:
name: Type Checking
command: yarn run type-check

legacy algoliasearch:
legacy algoliasearch v3:
<<: *defaults
steps:
- checkout
Expand All @@ -221,6 +225,25 @@ jobs:
name: Type Checking
command: yarn run type-check:v3

legacy algoliasearch v4:
<<: *defaults
steps:
- checkout
- *attach_workspace
- *install_yarn_version
- *restore_yarn_cache
- *run_yarn_install
- run:
name: Update dependencies
command: |
./scripts/legacy/downgrade-algoliasearch-v4.js
- run:
name: Unit & Integration tests
command: yarn run test
- run:
name: Type Checking
command: yarn run type-check

vue v3:
<<: *defaults
steps:
Expand Down
2 changes: 1 addition & 1 deletion packages/algoliasearch-helper/types/algoliasearch.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export type RecommendResponse<T> = PickForClient<{
export type RecommendResponses<T> = PickForClient<{
v3: any;
// @ts-ignore
v4: { results: Array<RecommendResponse<T>> };
v4: RecommendClient.RecommendQueriesResponse<T>;
// @ts-ignore
v5: AlgoliaSearch.GetRecommendationsResponse;
}>;
Expand Down
67 changes: 67 additions & 0 deletions scripts/legacy/downgrade-algoliasearch-v4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env node
const path = require('path');

const shell = require('shelljs');

const packageJsonPaths = [
path.resolve(__dirname, '../../package.json'),
...JSON.parse(
shell.exec(
"yarn run --silent lerna list --json --all --ignore='example-*'",
{
silent: true,
}
).stdout
).map(({ location }) => path.resolve(location, 'package.json')),
];

console.log(
`Downgrading algoliasearch dependency to v4 in:
- ${packageJsonPaths.join('\n- ')}`
);

// change main dependency
shell.sed(
'-i',
/"algoliasearch": "5.*"(,?)/,
'"algoliasearch": "4.23.2"$1',
packageJsonPaths
);

// Downgrade other dependency
shell.sed(
'-i',
/"@algolia\/client-search": "5.*"(,?)/,
'"@algolia/client-search": "4.23.2"$1',
packageJsonPaths
);

// remove resolution
shell.sed('-i', /"@algolia\/client-common": "5.*"(,?)/, '', packageJsonPaths);
shell.sed(
'-i',
/"places.js\/algoliasearch": "5.*"(,?)/,
'"places.js/algoliasearch": "4.23.2"$1',
packageJsonPaths
);

// replace import in examples
shell.sed(
'-i',
/import { liteClient as algoliasearch } from 'algoliasearch\/lite'/,
"import algoliasearch from 'algoliasearch/lite'",
...shell.ls('examples/*/*/*.{js,ts,tsx,vue}'),
...shell.ls('examples/*/*/{src,pages,app}/*.{js,ts,tsx,vue}')
);

// replace dependency in examples
shell.sed(
'-i',
/"algoliasearch": ".*"(,)?/,
'"algoliasearch": "4.23.2"$1',
...shell.ls('examples/*/*/package.json')
);

shell.exec('yarn install');

shell.exec('cp -r node_modules/algoliasearch-v4 node_modules/algoliasearch');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Struggled with yarn which still keeps 4.23.2 with the algoliasearch-v4 name, even if we remove the alias.

It does output some warnings like "warning Pattern is trying to unpack in the same destination" which may be related.

Copying it manually works though so idk if we should bother

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this is because of Create InstantSearch App